-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatteryStatus.py
More file actions
30 lines (21 loc) · 791 Bytes
/
Copy pathbatteryStatus.py
File metadata and controls
30 lines (21 loc) · 791 Bytes
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
import psutil
import sys
def check_battery(speak):
print("Checking battery status...")
battery_status = psutil.sensors_battery()
if battery_status is None:
print("Battery information not available.")
return
battery = battery_status.percent
charger_plugin = battery_status.power_plugged
if 30 >= battery >= 19 and not charger_plugin:
speak(f"Power levels are critically low , {battery} %")
elif battery < 10 and not charger_plugin:
speak("Low power detected.Closing all active applications....")
sys.exit()
else:
print(f"Battery capacity: {battery}%")
# if battery <=20 :
# print(f" battery : {battery}, initiated battery saver, i recommend you to plugin charger")
# else:
# check_battery()