-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsite-blocker-1st_draft.py
87 lines (76 loc) · 2.54 KB
/
website-blocker-1st_draft.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Program Architecture
# Mac and Linux: /etc/hosts
# Windows: c:\windows\Systems32\drivers\etc
# for windows machines...
#hosts_path="c:\windows\Systems32\drivers\etc\hosts"
#hosts_path=r"c:\windows\Systems32\drivers\etc\hosts" #... using the r flag to tell python you are passing a real string not a /w special char...
# or use this alternate solution:
#hosts_path="c:\\windows\\Systems32\\drivers\\etc\\hosts" # using two back slashes...
# for mac and linux machines...
import time
from datetime import datetime as dt # using the namespace dt for a more concise reference name in the code...
hosts_paths = "/etc/hosts"
# redirects to hosts machine...
redirect="127.0.0.1"
# websites to block during specific times of the day...
website_list=["www.facebook.com","facebook.com", "www.twitter.com", "twitter.com"]
# datetime.datetime(2018, 7, 10, 15, 59, 21, 697959) date, hour, minutes, seconds, micro seconds...
# can break script with ctrl c for mac...
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,16): # checking for working hours...8am to 16:00(4:00pm)
print("Working Hours... ")
else:
print("Fun Hours... ")
time.sleep(5)
print("Five seconds have past... " + str(dt.now().second)) # <----TypeError: must be str, not int due to passing dt.now().second)
# fixed it with str(dt.now().second))...converted int to string with str()...
"""
File "app3-website-blocker.py", line 28, in <module>
print("Five seconds have past... " + dt.now().second)
TypeError: must be str, not int
"""
"""------------------------PYTHON SHELL OUTPUT-----------------------------"""
""" python interactive shell
OUTPUT:
>>> from datetime import datetime as dt
>>> dt.now()
datetime.datetime(2018, 7, 10, 15, 59, 21, 697959)
>>>
>>> dt.now() < (2016,5,5,8)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'datetime.datetime' and 'tuple'
>>>
"""
"""
OUTPUT:
>>> dt.now() < dt(2016,5,5,8)
False
>>>
"""
"""
OUTPUT:
>>> dt.now().year
2018
>>> type(dt.now().year)
<class 'int'>
>>>
"""
"""
OUTPUT:
Five seconds have past... 50
Fun Hours...
Five seconds have past... 55
Fun Hours...
Five seconds have past... 0
Fun Hours...
Five seconds have past... 5
Fun Hours...
Five seconds have past... 10
Fun Hours...
^CTraceback (most recent call last):
File "app3-website-blocker.py", line 27, in <module>
time.sleep(5)
KeyboardInterrupt <-----typed ctrl c...same for Windows...
Martins-iMac:mapping martinbatista$
"""