-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
67 lines (56 loc) · 1.61 KB
/
main.py
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
64
65
66
67
import os
isblocked = False
blocktext = '# 127.0.0.1 www.facebook.com'
unblocktext = '127.0.0.1 www.facebook.com'
path = os.path.abspath("C:/Windows/System32/drivers/etc/hosts")
# print(path)
with open(path, "a+") as f:
f.seek(0)
doc = f.read()
if 'www.facebook.com' not in doc:
f.write('\n' + blocktext)
else:
if blocktext not in doc:
isblocked = True
def changeblockstatus():
global isblocked
with open(path, "a+") as f:
f.seek(0)
lines = f.readlines()
for c, line in enumerate(lines):
if 'facebook' in line:
if isblocked:
lines[c] = blocktext
isblocked = False
print('\nFacebook is now unblocked')
else:
lines[c] = unblocktext
isblocked = True
print('\nFacebook is now blocked')
with open(path, "w") as f:
f.writelines(lines)
print('Welcome to the Facebook disabling tool!')
print()
print()
if isblocked:
print('Facebook is currently blocked')
else:
print("Facebook is NOT currently blocked")
print()
while 1 > 0:
print()
print("""
------Options------
1. Block/Unblock Facebook (y/n)
2. Quit
3. (more features tbd)
""")
print()
choice = input(': ')
if choice == '1':
changeblockstatus()
elif choice == '2':
input('Press any key to exit:')
quit()
else:
print('invalid input, please choose one of the listed menu options')