-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
59 lines (47 loc) · 1.47 KB
/
app.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
49
50
51
52
53
54
55
56
57
58
59
import os
import time
import appindicator # type: ignore
import gtk # type: ignore
from pydexcom import Dexcom
ICON = os.path.abspath("./assets/icon.png")
USERNAME = os.getenv("USERNAME")
PASSWORD = os.getenv("PASSWORD")
def get_glucose():
dexcom = Dexcom(USERNAME, PASSWORD) # type: ignore
reading = dexcom.get_current_glucose_reading()
if reading:
return f"{reading.value}{reading.trend_arrow}".strip()
return "ERR"
class Indicator:
def __init__(self):
self.glucose = ""
self.ind = appindicator.Indicator(
"glucose-indicator", ICON, appindicator.CATEGORY_APPLICATION_STATUS
)
self.ind.set_status(appindicator.STATUS_ACTIVE)
self.update()
self.ind.set_menu(self.setup_menu())
def setup_menu(self):
menu = gtk.Menu()
refresh = gtk.MenuItem("Refresh Now")
refresh.connect("activate", self.on_refresh)
refresh.show()
menu.append(refresh)
return menu
def update(self):
INTERVAL = 300 # 5 minutes
while True:
try:
old = self.glucose
new = get_glucose()
if new != old:
self.glucose = new
self.ind.set_label(new)
except Exception as err:
print(f"ERR: {err}")
time.sleep(INTERVAL)
def on_refresh(self):
self.update()
if __name__ == "__main__":
app = Indicator()
gtk.main()