diff options
| author | Ultrabug <ultrabug@ultrabug.net> | 2015-02-23 12:02:29 +0100 |
|---|---|---|
| committer | Ultrabug <ultrabug@ultrabug.net> | 2015-02-23 12:02:29 +0100 |
| commit | 1a3f63743e09b74d7901b42aecd1d9e0b87c79bd (patch) | |
| tree | c1bfb820b2b31e68e338627f8903bc3c20cb45f3 | |
| parent | 43b39ebad5cdf3a9e99ef1d6b1ec5ebd8d1620f4 (diff) | |
| parent | e9c1b5a579a1e5beb195b23c9597a70944d218c1 (diff) | |
Merge pull request #68 from thomas-/battery_level_py3_fix
fix battery_level module compatibility with python3 by @thomas-
| -rw-r--r-- | py3status/modules/battery_level.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/py3status/modules/battery_level.py b/py3status/modules/battery_level.py index 5ca9ea8..fd7c22d 100644 --- a/py3status/modules/battery_level.py +++ b/py3status/modules/battery_level.py @@ -47,13 +47,13 @@ class Py3status: # Example acpi raw output: "Battery 0: Discharging, 43%, 00:59:20 remaining" acpi_raw = subprocess.check_output(["acpi"], stderr=subprocess.STDOUT) - acpi_clean = acpi_raw.translate(None, ',') + acpi_unicode = acpi_raw.decode("UTF-8") # Example list: ['Battery', '0:', 'Discharging', '43%', '00:59:20', 'remaining'] - acpi_list = acpi_clean.split(' ') + acpi_list = acpi_unicode.split(' ') - charging = True if acpi_list[2] == "Charging" else False - percent_charged = int(acpi_list[3].translate(None, '%')) + charging = True if acpi_list[2][:8] == "Charging" else False + percent_charged = int(acpi_list[3][:-2]) self.time_remaining = ' '.join(acpi_list[4:]) battery_full = False @@ -112,3 +112,10 @@ class Py3status: stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w') ) + +if __name__ == "__main__": + from time import sleep + x = Py3status() + while True: + print(x.battery_level([], {})) + sleep(1) |
