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 4a8bf7b

Browse files
Merge pull request avinashkranjan#746 from pankaj892/master
Added Battery Notification Script
2 parents 16b398f + 5873386 commit 4a8bf7b

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import psutil
2+
from plyer import notification
3+
import time
4+
#From psutil we import sensors battery class which gives us battery percentage
5+
threshold = int(input('Enter the threshold: '))
6+
7+
battery = psutil.sensors_battery()
8+
percent = battery.percent
9+
10+
while(True):
11+
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+
continue

‎Battery-Notification/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This is a Python Script which shows the battery percentage left
2+
3+
## Requirements
4+
5+
For this script to run you need to have psutil and plyer packages installed
6+
7+
Run the command in terminal to install package
8+
9+
```
10+
$ pip install psutil
11+
```
12+
```
13+
$ pip install plyer
14+
```
15+
Run the program using command
16+
17+
```
18+
$ python Battery-Notification.py
19+
```

0 commit comments

Comments
(0)

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