-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_program.pyw
36 lines (29 loc) · 996 Bytes
/
main_program.pyw
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
import notifypy
import psutil
import time
def notification(title, text):
n = notifypy.Notify()
n.title = title
n.message = text
n.send(block=False)
warn_p = int(open("config.txt").read())
while True:
battery = psutil.sensors_battery()
plug = battery.power_plugged
if plug == True:
time.sleep(15)
else:
notification("On Battery", "Power Source Disconnected")
time.sleep(25)
battery = psutil.sensors_battery()
plug = battery.power_plugged
lev = int(battery.percent)
while plug == False:
battery = psutil.sensors_battery()
plug = battery.power_plugged
if (int(battery.percent) <= warn_p) and (int(battery.percent)!= lev):
notification("Emergency", ("The Power is at "+str(batter.percent)))
lev = int(battery.percent)
time.sleep(10)
else:
notification("Charger Connected", "Power source is now restored")