63 lines
1.7 KiB
Python
Executable File
63 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import subprocess
|
|
|
|
|
|
BATTERY_ZERO_DATA = subprocess.check_output(["upower", "-i", "/org/freedesktop/UPower/devices/battery_BAT0"]).decode('utf-8')
|
|
BATTERY_ONE_DATA = subprocess.check_output(["upower", "-i", "/org/freedesktop/UPower/devices/battery_BAT1"]).decode('utf-8')
|
|
|
|
BATTERY_STATE_MAP = {
|
|
'charging': "",
|
|
'fully-charged': "",
|
|
'empty': "",
|
|
}
|
|
|
|
bat_0 = {}
|
|
bat_1 = {}
|
|
|
|
|
|
def get_upower_value(data, key):
|
|
return data.split(key)[-1].split('\n')[0].strip()
|
|
|
|
|
|
def parse_battery_data(data, obj):
|
|
obj['state'] = get_upower_value(data, 'state:')
|
|
obj['percentage'] = get_upower_value(data, 'percentage:')
|
|
|
|
if obj['state'] not in BATTERY_STATE_MAP:
|
|
bat_level = int(obj['percentage'].strip('%'))
|
|
|
|
if bat_level < 10:
|
|
obj['icon'] = ""
|
|
elif 20 > bat_level >= 10:
|
|
obj['icon'] = ""
|
|
elif 30 > bat_level >= 20:
|
|
obj['icon'] = ""
|
|
elif 40 > bat_level >= 30:
|
|
obj['icon'] = ""
|
|
elif 50 > bat_level >= 40:
|
|
obj['icon'] = ""
|
|
elif 60 > bat_level >= 50:
|
|
obj['icon'] = ""
|
|
elif 70 > bat_level >= 60:
|
|
obj['icon'] = ""
|
|
elif 80 > bat_level >= 70:
|
|
obj['icon'] = ""
|
|
elif 90 > bat_level >= 80:
|
|
obj['icon'] = ""
|
|
elif 100 > bat_level >= 90:
|
|
obj['icon'] = ""
|
|
else:
|
|
obj['icon'] = ""
|
|
|
|
else:
|
|
obj['icon'] = BATTERY_STATE_MAP.get(obj['state'], "")
|
|
|
|
|
|
parse_battery_data(BATTERY_ZERO_DATA, bat_0)
|
|
parse_battery_data(BATTERY_ONE_DATA, bat_1)
|
|
|
|
print(f"{bat_0['icon']} {bat_0['percentage']} {bat_1['icon']} {bat_1['percentage']}")
|
|
|
|
|