Skip to content

Instantly share code, notes, and snippets.

@pinguinson
Created September 26, 2015 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinguinson/aecf32d09ee24abdbb48 to your computer and use it in GitHub Desktop.
Save pinguinson/aecf32d09ee24abdbb48 to your computer and use it in GitHub Desktop.
#!/bin/python
import subprocess, time
target = 100
step = 5
cur_target = target
while True:
if "Discharging" in str(subprocess.check_output(["cat", "/sys/class/power_supply/BAT0/status"])):
aux = subprocess.check_output(["acpi"])
acpi_res = aux.split()
n = len(acpi_res[3])
battery_level = int(acpi_res[3][:n-2])
if battery_level <= cur_target:
message = "Battery is low! " + str(battery_level) + "% left!"
subprocess.call(["notify-send", "-u", "critical", "-t", "5000", message])
cur_target = min(cur_target - step, battery_level - step)
subprocess.call(["echo", str(cur_target)])
else:
cur_target = target
subprocess.call(["echo", str(cur_target)])
time.sleep(30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment