这是一个相当初学者的问题,因为我对编码非常陌生……如果您能指导我的话,将会非常感谢您
import time
from datetime import datetime as dt
host_file = r"C:\Windows\System32\drivers\etc\hosts"
host_temp = "hosts"
redirect = "127.0.0.1"
website_list=['facebook.com','www.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(host_temp , "r+") as file:
content = file.read()
for web in website_list:
if web in content:
pass
else:
file.write(redirect+website_list)
else:
print("fun hours .....")
time.sleep(5)