home · archive · links · projects

battery.py

Show laptop battery status

#!/usr/bin/env python3

now = 0
full = 0
with open('/sys/class/power_supply/BAT1/energy_now') as fp:
    now = float(fp.read())
with open('/sys/class/power_supply/BAT1/energy_full') as fp:
    full = float(fp.read())

per = str(int(now * 100/ full))
print(per + "%")

© Licensed under CC BY-NC-SA 4.0 if not specified otherwise.
Email: dzshy [at] outlook [dot] com