Code: Select all
Batt:${color e0e0e0} .$acpiacadapter, ${color e0e0e0} ${battery_percent BAT0}% ${color e0e0e0} ${execi 300 /home/harry/.battery.sh} | ${color}BATTERY:${color e0e0e0} ${battery_bar 7,50 BAT0} ${execi 300 /home/harry/.battery.sh}
Be sure to change /home/harry with /home/your user name/.battery.sh
Code: Select all
#!/usr/bin/env python
import os, math
from decimal import *
rate = 0.0
batteries = os.listdir("/sys/class/power_supply")
output ="No Data"
for battery in batteries:
if"BAT" in battery:
status = open("/sys/class/power_supply/%s/status" % (battery)).read().strip("\n")
if"Discharging" in status:
energy = Decimal(open("/sys/class/power_supply/%s/energy_now" % (battery)).read())
power = Decimal(open("/sys/class/power_supply/%s/power_now" % (battery)).read())
if power > 0:
hours = math.floor(energy / power)
minutes = math.floor(((energy % power) / power) * 60)
output ="%.0f hours %.0f minutes" % (hours, minutes)
else:
output ="Gathering"
else:
output = status
print output