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 6b16b1a

Browse files
Update Battery-Notification.py
1 parent 54daeb9 commit 6b16b1a

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

‎Battery-Notification/Battery-Notification.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
from plyer import notification
33
import time
44
#From psutil we import sensors battery class which gives us battery percentage
5+
threshold = int(input('Enter the threshold: '))
56
while(True):
67
battery = psutil.sensors_battery()
78
percent = battery.percent
8-
notification.notify(
9-
title = "Battery Percentage",
10-
message = str(percent) + "% Battery Remaining",
11-
timeout = 5
12-
)
13-
#After every 60 minutes it will show the battery percentage via a notification
14-
time.sleep(60)
9+
time.sleep(60*2)
10+
battery = psutil.sensors_battery()
11+
cur_per = battery.percent
12+
change = cur_per - percent
13+
diff = abs(change)
14+
#We calculate the change in the battery and show notification if battery level increases or decreases
15+
if(diff >= threshold):
16+
notification.notify(
17+
title = "Battery Percentage",
18+
message = str(percent) + "% Battery Remaining",
19+
timeout = 5
20+
)
1521
continue

0 commit comments

Comments
(0)

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