-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpowerNotifier.pyw
More file actions
71 lines (55 loc) · 2.04 KB
/
Copy pathpowerNotifier.pyw
File metadata and controls
71 lines (55 loc) · 2.04 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
64
65
66
67
68
69
70
71
import psutil
from win10toast import ToastNotifier
import time
import schedule
ico_path1 = '../icon2.ico'
ico_path2 = '../icon1.ico'
def notify_start():
toast = ToastNotifier()
toast.show_toast('Batter Alert',
'Power notifier is running...',
duration=5,
icon_path=ico_path1)
def notify_error():
toast = ToastNotifier()
toast.show_toast('Battery Notifier Error',
'Unexpected Error Ocurred: Closing Power Notifier...',
duration=5,
icon_path=ico_path1)
def power_info():
battery = psutil.sensors_battery()
plugged_in = battery.power_plugged
return plugged_in, battery.percent
def notify_fullcharge():
toast = ToastNotifier()
toast.show_toast('Battery Alert (>97%)',
'Battery is fully charged: {}%.'.format(battery_percent),
duration=5,
icon_path=ico_path1)
def notify_batterylow():
toast = ToastNotifier()
toast.show_toast('Battery Alert (<15%)',
'Battery is about to be discharged: {}%.'.format(battery_percent),
duration=5,
icon_path=ico_path2)
notify_start()
try:
def Battery_Alert():
plugged_in, battery_percent = power_info()
# print(plugged_in)
if plugged_in == True:
print('Power Plugged_in = True\nBattery Percentage: {}%'.format(battery_percent))
if battery_percent >= 97:
notify_fullcharge()
else:
_, battery_percent = power_info()
print('Power plugged_in = False\nBattery Percentage: {}%'.format(battery_percent))
if battery_percent <= 15:
notify_batterylow()
schedule.every(59).seconds.do(Battery_Alert)
while True:
schedule.run_pending()
time.sleep(1)
except:
print('Unexpected Error Occured: Closing Batter Notifier...')
notify_error()