Created
August 6, 2017 17:48
-
-
Save whalehulk/643d62e09ac16d2be879e67192b81632 to your computer and use it in GitHub Desktop.
a simple website blocker for everyone for concentrating on work :).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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