forked from aman-raza/Friends_Hack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notification_for_battery_status.py
50 lines (45 loc) · 1.64 KB
/
notification_for_battery_status.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
#!/usr/bin/env python3
"""install some library by using pip in terminal."""
# pip install psutil
# pip install time
# pip install pyttsx3
# pip install win10toast
import psutil
import time
import pyttsx3
from win10toast import ToastNotifier # also need to install win32api
import threading
toaster = ToastNotifier()
x=pyttsx3.init()
x.setProperty('rate',110)
x.setProperty('volume',3)
count = 0
def show_notification(show_text):
toaster.show_toast(show_text,
icon_path='battery_indicator.ico',
duration=10)
# loop the toaster over some period of time
while toaster.notification_active():
time.sleep(0.005)
def monitor():
while (True):
time.sleep(1)
battery = psutil.sensors_battery()
plugged = battery.power_plugged
percent = int(battery.percent)
# You can change below int 35 to 25or less for your low-battery notification.
if percent < 35:
if plugged == False:
processThread = threading.Thread(target=show_notification, args=("Your Battery at "+str(percent)+"% Please plug the cable",)) # <- note extra ','
processThread.start()
x.say("Your battery is getting low so charge it right now")
x.runAndWait()
elif percent >= 98:
if plugged == True:
processThread = threading.Thread(target=show_notification, args=("Charging is getting complete",)) # <- note extra ','
processThread.start()
x.say("Charging is getting complete")
x.runAndWait()
if __name__ == "__main__":
monitor()
# to stop notification plug-out / plug-in charging cable .