-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFocusMode.py
More file actions
63 lines (53 loc) · 1.92 KB
/
FocusMode.py
File metadata and controls
63 lines (53 loc) · 1.92 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import time
import datetime
import ctypes,sys
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
if is_admin():
current_time = datetime.datetime.now().strftime("%H:%M")
Stop_time = input("Enter time example:- [10:10]:- ")
a = current_time.replace(":",".")
a = float(a)
b = Stop_time.replace(":",".")
b = float(b)
Focus_Time = b-a
Focus_Time = round(Focus_Time,3)
host_path ='C:\Windows\System32\drivers\etc\hosts'
redirect = '127.0.0.1'
print(current_time)
time.sleep(2)
website_list = ["www.facebook.com","facebook.com"]
if (current_time < Stop_time):
with open(host_path,"r+") as file:
content = file.read()
time.sleep(2)
for website in website_list:
if website in content:
pass
else:
file.write(f"{redirect} {website}\n")
print("DONE")
time.sleep(1)
print("FOCUS MODE TURNED ON !!!!")
while True:
current_time = datetime.datetime.now().strftime("%H:%M")
website_list = ["www.facebook.com","facebook.com"]
if (current_time >= Stop_time):
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 website_list):
file.write(line)
file.truncate()
print("Websites are unblocked !!")
file = open("focus.txt","a")
file.write(f",{Focus_Time}")
file.close()
break
else:
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
is_admin()