battery.py 437 B

12345678910111213141516171819
  1. # pip install psutil
  2. import psutil
  3. battery = psutil.sensors_battery()
  4. plugged = battery.power_plugged
  5. percent = battery.percent
  6. if percent <= 30 and plugged!=True:
  7. # pip install py-notifier
  8. # pip install win10toast
  9. from pynotifier import Notification
  10. Notification(
  11. title="Battery Low",
  12. description=str(percent) + "% Battery remain!!",
  13. duration=5, # Duration in seconds
  14. ).send()