-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
48 lines (41 loc) · 1011 Bytes
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json
import threading
import psutil
import minidiagram
import payload
timer = None
cpu_percent = [0] * 80
def record_data():
global cpu_percent
cpu_percent.append(psutil.cpu_percent())
cpu_percent.pop(0)
def get_config():
global cpu_percent
diagram = minidiagram.MiniDiagram(bgcolor=(0.6,0.6,0.6))
diagram.add_data(cpu_percent, (1,0,0))
return {
"ttl": 1,
"indicators": [
{
"icon": diagram.get_data_uri(),
"title": "{cpu: =5.1f}%".format(cpu=cpu_percent[-1])
}
],
"menu": [
{
"title": "Throttle!",
"active": False,
"open": "https://google.com"
}
],
}
def update():
global timer
record_data()
payload.set(json.dumps(get_config()).encode())
timer = threading.Timer(1.0, update)
timer.start()
def run():
global timer
timer = threading.Timer(1.0, update)
timer.start()