-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebsite_Blocker.py
29 lines (26 loc) · 909 Bytes
/
Website_Blocker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# pip install DateTime
import datetime
import time
end_time = datetime.datetime(2023, 1, 12)
site_block = ["www.facebook.com"]
host_path = "C:/Windows/System32/drivers/etc/hosts"
redirect = "127.0.0.1"
while True:
if datetime.datetime.now() < end_time:
print("Start Blocking")
with open(host_path, "r+") as host_file:
content = host_file.read()
for website in site_block:
if website not in content:
host_file.write(redirect + " " + website + "\n")
else:
pass
else:
with open(host_path, "r+") as host_file:
content = host_file.read()
host_file.seek(0)
for lines in content:
if not any(website in lines for website in site_block):
host_file.write(lines)
host_file.truncate()
time.sleep(5)