Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
28 lines (28 loc) · 1.23 KB

File metadata and controls

28 lines (28 loc) · 1.23 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
hosts_path = r"/etc/hosts" // r is for raw string
hosts_temp = "hosts"
redirect = "127.0.0.1"
web_sites_list = ["www.facebook.com", "facebook.com"] // users can modify the list of the websites they want to block
while True:
if dt(dt.now().year, dt.now().month, dt.now().day, 9) < dt.now() < dt(dt.now().year, dt.now().month, dt.now().day,22):
print("Working hours")
with open(hosts_path, "r+") as file:
content = file.read()
for website in web_sites_list:
if website in content:
pass
else:
file.write(redirect+" "+website+"\n")
else:
print("Fun time")
with open(hosts_path, "r+") as file:
content = file.readlines()
file.seek(0) // reset the pointer to the top of the text file
for line in content:
// here comes the tricky line, basically we overwrite the whole file
if not any(website in line for website in web_sites_list):
file.write(line)
// do nothing otherwise
file.truncate() // this line is used to delete the trailing lines (that contain DNS)
time.sleep(5)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.