Skip to content

Instantly share code, notes, and snippets.

@sekomer
Created October 9, 2022 10:14
Show Gist options
  • Save sekomer/7dad39a7ffc720d6843173120073b8e0 to your computer and use it in GitHub Desktop.
Save sekomer/7dad39a7ffc720d6843173120073b8e0 to your computer and use it in GitHub Desktop.
python script that calculates remaining battery health
#!/bin/python3
import os
import sys
"""
read terminal output
https://stackoverflow.com/q/3503879/12688015
"""
design = os.popen("upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep energy-full-design").read()
current = os.popen("upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep energy-full:").read()
design = int(''.join(i for i in design if i.isdecimal()))
current = int(''.join(i for i in current if i.isdecimal()))
print(f'Design: {design//10000}')
print(f'Current: {current//10000}')
print(f"Current max battery capacity: {round(current/design, 2)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment