import time
from datetime import datetime

hosts_path = r'C:\Windows\System32\drivers\etc\hosts'
hosts_temp = 'hosts'
redirect = '127.0.0.1'
website_list = ['www.facebook.com','facebook.com']

while True:
    if dt(dt.now().year, dt.now().month, dt.now().day, 8) < dt.now() < dt(dt.now().year, dt.now().month, dt.now().day, 18):
        print('Working hours')
        with open(hosts_path,'r+') as file:
            content=file.read()
            for website in website_list:
                if website in content:
                    pass
                else:
                    file.write(redirect+' '+website+'\n')
    else:
        with open(hosts_path, '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.write(line)
            file.truncate()
        print('not supposed to be doing work right now')
    time.sleep(30)

#run me with admin privs.
# Use Task scheduler to run me as soon as windows starts.
#.pyw extension is the proper file to run, the .py file was used to build the script
