-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathapp v2.py
More file actions
22 lines (20 loc) · 970 Bytes
/
app v2.py
File metadata and controls
22 lines (20 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import time
# Add the websites that you want to block to this list
websites_to_block = ["www.facebook.com", "www.twitter.com", "www.instagram.com"]
while True:
current_time = time.localtime()
# Set the time range in which the websites should be blocked
if current_time.tm_hour >= 9 and current_time.tm_hour < 18:
with open(r"C:\Windows\System32\drivers\etc\hosts", "w") as file:
for website in websites_to_block:
file.write(f"127.0.0.1 {website}\n")
else:
# Remove the website block if it's outside the set time range
with open(r"C:\Windows\System32\drivers\etc\hosts", "w+") as file:
lines = file.readlines()
for line in lines:
if not any(website in line for website in websites_to_block):
file.write(line)
file.truncate()
# Set the time interval at which to check the current time
time.sleep(60)