Skip to content

Instantly share code, notes, and snippets.

@whalehulk
Created August 6, 2017 17:48
Show Gist options
  • Save whalehulk/643d62e09ac16d2be879e67192b81632 to your computer and use it in GitHub Desktop.
Save whalehulk/643d62e09ac16d2be879e67192b81632 to your computer and use it in GitHub Desktop.
a simple website blocker for everyone for concentrating on work :).
import time
from datetime import datetime as dt
localhost="127.0.0.1"
website_list=["www.facebook.com","facebook.com"]
start=input("Hey Enter Starting of ur working hours !")
end=input("Hey Enter Ending Time of ur working hours ?")
host_temp=r"C:\Windows\System32\drivers\etc\hosts"
while True:
if dt(dt.now().year,dt.now().month,dt.now().day,int(start)) < dt.now() < dt(dt.now().year,dt.now().month,dt.now().day,int(end)):
print("let me check the time! Wait for fun Hours :)")
print(dt.now())
with open (host_temp,'r+') as file:
content= file.read()
print(content)
for website in website_list:
if website in content:
pass
else:
file.write(localhost + " " + 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.writelines(line)
file.truncate()
print("Fun Hours!")
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment