Skip to content

Commit 94985a3

Browse files
committed
Added Battery Notification Script
Signed-off-by: Pankaj Biradar <[email protected]>
1 parent 64ef8bc commit 94985a3

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
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

Diff for: AutomationScripts/Battery Notification/README.md

+19
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)