-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsite_blocker1.pyw
28 lines (26 loc) · 1022 Bytes
/
website_blocker1.pyw
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
import time
from datetime import datetime as dt
host_temp=r"E:\Rahul\Projects\Python Projects\Website Blocker Application\hosts"
host_path= r"C:\Windows\System32\drivers\etc"
redirect = "127.0.0.1"
website_list = ["www.facebook.com", "facebook.com"]
while True:
if dt(dt.now().year, dt.now().month, dt.now().day, 8) < dt.now() < dt(dt.now().year, dt.now().month, dt.now().day, 18):
print ("Working hours..")
with open(host_temp,'r+') as file:
content=file.read()
for website in website_list:
if website in content:
pass
else:
file.write(redirect + " " + website+ "\n")
else:
with open(host_temp, 'r+') as file:
content= file.readlines()
file.seek(0)
for line in content:
if not any(website in line for website in website_list):
file.write(line)
file.truncate()
print("Fun hours..")
time.sleep(5)