-
Notifications
You must be signed in to change notification settings - Fork 0
/
nsnotifier.py
executable file
·50 lines (35 loc) · 1.35 KB
/
nsnotifier.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
#!/usr/bin/python
import json, urllib2, os
from time import strftime, gmtime, localtime
ns_url = "http://yours.nightscout_address.com/"
min = 80
max = 160
def notify(title, subtitle, message):
t = '-title {!r}'.format(title)
s = '-subtitle {!r}'.format(subtitle)
m = '-message {!r}'.format(message)
snd = '-sound \'default\''
url = '-open %s' % ns_url
group = '-group 666000666'
appIcon = '-appIcon http://www.nightscout.info/wp-content/uploads/2014/07/Nightscout.png'
os.system('/usr/local/bin/terminal-notifier {}'.format(' '.join([m, t, s, snd, url, appIcon, group])))
j = urllib2.urlopen('%s/pebble' % ns_url)
data = json.load(j)
cur_time = data['status'][0]['now']
read_time = data['bgs'][0]['datetime']
if cur_time - read_time > 1800000:
lost_time = strftime("%d %b %Y %H:%M",localtime(read_time/1000))
notify(title = 'Nightscout read.',
subtitle = strftime("%d %b %H:%M",localtime(cur_time/1000)),
message = 'I\'ve lost parakeet signal at: %s' % (lost_time))
else:
bwpo = data['bgs'][0]['sgv']
bgdelta = data['bgs'][0]['bgdelta']
if bgdelta > 0:
bgdelta_s = "+%s" % bgdelta
else:
bgdelta_s = "%s" % bgdelta
if bwpo < min or bwpo > max:
notify(title = 'Nightscout read.',
subtitle = '',
message = 'Sugar: %s, change: %s' % (bwpo, bgdelta_s))