Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0d86656

Browse files
pankaj892kaustubhgupta
andauthored
Update Battery-Notification/Battery-Notification.py
Co-authored-by: Kaustubh Gupta <kaustubhgupta1828@gmail.com>
1 parent 6b16b1a commit 0d86656

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

‎Battery-Notification/Battery-Notification.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,24 @@
33
import time
44
#From psutil we import sensors battery class which gives us battery percentage
55
threshold = int(input('Enter the threshold: '))
6+
7+
battery = psutil.sensors_battery()
8+
percent = battery.percent
9+
610
while(True):
711
battery = psutil.sensors_battery()
12+
cur_per = battery.percent
13+
change = cur_per - percent
14+
diff = abs(change)
15+
#We calculate the change in the battery and show notification if battery level increases or decreases
16+
if(diff >= threshold):
17+
notification.notify(
18+
title = "Battery Percentage",
19+
message = str(cur_per) + "% Battery Remaining",
20+
timeout = 5
21+
)
22+
percent = cur_per
23+
battery = psutil.sensors_battery()
824
percent = battery.percent
925
time.sleep(60*2)
1026
battery = psutil.sensors_battery()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /