-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
83 lines (60 loc) · 2.23 KB
/
app.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
import os
from datetime import datetime, timedelta
from win10toast import ToastNotifier
def push_notification(title: str, message: str) -> None:
"""
Display a toast notification.
"""
toaster = ToastNotifier()
duration = 30
toaster.show_toast(title, message, duration=duration, threaded=True)
def save(filepath: str, value: str) -> None:
"""
Save value to a file.
"""
with open(filepath, 'w', encoding='utf-8') as file:
file.write(str(value))
def load(filepath: str) -> str:
"""
Load the content from a file.
"""
with open(filepath, 'r', encoding='utf-8') as file:
return file.read()
if __name__ == '__main__':
# the number of days between each reminder
days = 5
# the file name that contains the next reminder date
filename = 'WindowsUpdateTrigger.txt'
# get the user folder absolute path
# this will output the path is this format: C:/Users/youruser
user_path = os.environ['USERPROFILE']
# get the absolute path of the file
filepath = os.path.join(user_path, filename)
# get current date
now = datetime.now()
# check if the file exist
if os.path.exists(filepath):
# load the file content
target_date = load(filepath)
# convert file content to datetime object
target_date = datetime.strptime(target_date, '%d-%m-%Y %H:%M:%S')
# check if the date inside the file is greater or equal to the current date
if now > target_date:
push_notification(
'Windows Update!', 'Check your Windows 10 for any potential updates.')
# set the reminder date
next_date = now + timedelta(days=days)
# convert datetime object the str format
next_date = next_date.strftime('%d-%m-%Y %H:%M:%S')
# save the remainder date in a file
save(filepath, next_date)
else:
print('Still Time')
# if the file does not exist
else:
# set the reminder date
next_date = now + timedelta(days=days)
# convert datetime object the str format
next_date = next_date.strftime('%d-%m-%Y %H:%M:%S')
# save the remainder date in a file
save(filepath, next_date)