2016-10-07 14:20:45 +03:00
|
|
|
#!/usr/bin/python3 -u
|
|
|
|
|
|
|
|
import time
|
|
|
|
import psutil
|
|
|
|
|
|
|
|
def status_print(status_msg):
|
|
|
|
prefix = '['
|
|
|
|
postfix = ']'
|
|
|
|
result = list()
|
|
|
|
for element in status_msg:
|
|
|
|
result.append('{"full_text":"' + element + '"}')
|
|
|
|
print(prefix + ','.join(result) + postfix)
|
|
|
|
|
|
|
|
print('{"version":1}\n[')
|
|
|
|
while True:
|
|
|
|
values = list()
|
2016-10-10 10:47:18 +03:00
|
|
|
current_time = time.strftime('%H:%M')
|
2016-10-07 14:20:45 +03:00
|
|
|
values.append(current_time)
|
2016-10-10 10:47:18 +03:00
|
|
|
current_day = time.strftime('%a %d')
|
|
|
|
values.append(current_day)
|
2016-10-07 14:20:45 +03:00
|
|
|
mem = psutil.virtual_memory()
|
2016-10-07 16:19:55 +03:00
|
|
|
memory = 'RAM: {}% ({}G)'.format(round(100.0 - mem.percent, 2),
|
|
|
|
round(mem.available / 2**30, 2))
|
2016-10-07 14:20:45 +03:00
|
|
|
values.append(memory)
|
2016-10-07 16:19:55 +03:00
|
|
|
with open('/sys/class/power_supply/BAT0/capacity', 'r') as capacity, \
|
|
|
|
open('/sys/class/power_supply/BAT0/status', 'r') as status:
|
2016-10-07 14:20:45 +03:00
|
|
|
batt_status = status.read().strip()
|
|
|
|
batt_capacity = capacity.read().strip()
|
|
|
|
if batt_status != 'Discharging':
|
|
|
|
batt_status = '↑'
|
|
|
|
else:
|
|
|
|
batt_status = '↓'
|
|
|
|
batt = 'BAT: ' + batt_capacity + '% ' + batt_status
|
|
|
|
values.append(batt)
|
|
|
|
values.reverse()
|
|
|
|
status_print(values)
|
|
|
|
time.sleep(5)
|
|
|
|
print(',', end='')
|