Skip to content

Instantly share code, notes, and snippets.

@yunazuno
Created December 25, 2011 17:55
Show Gist options
  • Save yunazuno/1519549 to your computer and use it in GitHub Desktop.
Save yunazuno/1519549 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import dbus
bat_bus = dbus.SystemBus()
bat_object = bat_bus.get_object('org.freedesktop.UPower',
'/org/freedesktop/UPower/devices/battery_BAT0')
bat_interface = dbus.Interface(bat_object,
'org.freedesktop.DBus.Properties')
percentage = bat_interface.Get("org.freedesktop.UPower.Device",
"Percentage"
).real
print percentage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment