forked from Antonynirmal11/Website-Blocker-Using-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebsiteBlocker.py
More file actions
31 lines (29 loc) · 1.07 KB
/
Copy pathWebsiteBlocker.py
File metadata and controls
31 lines (29 loc) · 1.07 KB
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
from time import *
from datetime import *
host_path = r"C:\Windows\System32\drivers\etc\hosts"
redirect = "127.0.0.1"
websites = []
n=int(input("Enter the number of Websites to be blocked:"))
print("Enter the url of the website:")
for i in range(n):
x=input()
websites.append(x)
if datetime(datetime.now().year,datetime.now().month,datetime.now().day,9)<datetime.now()<datetime(datetime.now().year,datetime.now().month,datetime.now().day,16
):
with open(host_path,"r+") as fileptr:
print("website blocked")
content = fileptr.read()
for website in websites:
if website in content:
pass
else:
fileptr.write(redirect+"\t"+website+"\n")
else:
with open(host_path,'r+') as file:
content = file.readlines();
file.seek(0)
for line in content:
if not any(website in line for website in websites):
file.write(line)
file.truncate()
print("website unblocked")