And so I did.
Here's what the output looks like:
Here's the code [Image]:
Here's the code again[plain text]:
#!/usr/bin/python
# The full charge.
cf = open('/sys/class/power_supply/BAT0/charge_full')
cf = int(cf.readline().strip('\n'))
#The current battery charge
cn = open('/sys/class/power_supply/BAT0/charge_now')
cn = int(cn.readline().strip('\n'))
st = open('/sys/class/power_supply/BAT0/status')
st = st.readline().strip('\n')
# Creating the Percentage
percent = (cn / cf) * 100
# Creating the Rounded Percentage
percents = str(percent)[0:2]
rpercent = int(percents)
def batMon(cf, cn, st):
# Testing Whether or not it is Charging
if rpercent == 20 and st != "Charging":
print("\n!!!! Battery is low! Please charge it now!!!!")
print("\n[Charging]: %s" % st)
# Printing out the total Voltage to the console
print("[Total Charge]: %d" % cf)
# Printing out the current voltage to the console
print("[Current Charge]: %d" % cn)
# Printing out the Rounded and the actual percentage
print("[Round Percent / Percent]: %s / %.2f" % (rpercent, percent))
if __name__ == "__main__":
batMon(cf, cn, st)
This was a pet project of mine for a while. I just recently decided to get into it. It's released under GNU GPLv3.
No comments:
Post a Comment