You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.0 KiB

4 years ago
import json
import time
import sys
def Compose():
header = {"version": 1}
tim = Time()
bat = Battery()
# body = json.dumps(tim) +","+ json.dumps(bat)
body = json.dumps(tim)
sys.stdout.write(body)
def Time():
t = time.localtime()
tstr = str(t.tm_hour) + ":" + str(t.tm_min)
tstrl = tstr + ":" + str(t.tm_sec)
dstr = str(t.tm_mday) + "." + str(t.tm_mon) + "." + str(t.tm_year)
b = {
"full_text": tstrl + " " + dstr,
"short_text": tstr,
"name": "clock",
"align": "center"
}
return b
def Battery():
bat = open("/sys/class/power_supply/BAT0/capacity")
level = int(bat.read())
bat.close
state = open("/sys/class/power_supply/BAT0/status")
sstring = str(state.read())
state.close
b = {
"full_text": str(level),
"short_text": str(level),
"name": "battery"
}
if sstring == "Charging":
b['color'] = "#a1fcbcff"
if sstring == "Discharging" and level <= 15:
b['color'] = "#ea6069ff"
return b
Compose()