|
2 | 2 | from plyer import notification
|
3 | 3 | import time
|
4 | 4 | #From psutil we import sensors battery class which gives us battery percentage
|
| 5 | +threshold = int(input('Enter the threshold: ')) |
5 | 6 | while(True):
|
6 | 7 | battery = psutil.sensors_battery()
|
7 | 8 | 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 | + ) |
15 | 21 | continue
|
0 commit comments