Created
October 9, 2022 10:14
-
-
Save sekomer/7dad39a7ffc720d6843173120073b8e0 to your computer and use it in GitHub Desktop.
python script that calculates remaining battery health
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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