-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_website.py
38 lines (31 loc) · 1.06 KB
/
block_website.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
30
31
32
33
34
35
import time
from datetime import datetime as dt
hosts = "/etc/hosts"
redirect = "127.0.10.100"
websites = ['www.facebook.com','facebook.com']
d = dt.now()
while True:
if dt(d.year,d.month,d.day,21) < d < dt(d.year,d.month,d.day,22):
print 'working hours !!!'
with open("/tmp/hosts",'r+') as f:
content = f.read()
for i in websites:
if i in content:
pass
else:
f.write(redirect+' '+i+"\n")
else:
print 'fun hours...'
with open("/tmp/hosts",'r+') as file:
con = file.readlines()
print con
file.seek(0)
for line in con:
# print line
if not any( webs in line for webs in websites):
# print 'writing this line',line
file.write(line)
else:
print 'i wont write this line',line
file.truncate()
time.sleep(5)