File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments