forked from MarieT1D/filter_es_test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getData.py
36 lines (30 loc) · 1.1 KB
/
getData.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
import requests, json, hashlib, urllib, datetime
from dateutil.parser import parse
from secret import NS_URL, NS_SECRET
NS_AUTHOR = "xDrip-NSEmulator"
TIMEZONE = "Europe/Berlin"
def get_sgv_from_ns(cnt):
data = get_from_nightscout(cnt)
result = []
for x in data:
result.append(x['sgv'])
return result
def get_from_nightscout(cnt):
#last = requests.get(NS_URL + 'api/v1/treatments?count=1&find[eventType]='+urllib.parse.quote('Exercise'), headers={
#last = requests.get(NS_URL + 'api/v1/treatments?count=1&find[enteredBy]='+urllib.parse.quote(NS_AUTHOR), headers={
last = requests.get(NS_URL + 'api/v1/entries?count='+str(cnt)+'&find[type]=sgv&find[device]='+urllib.parse.quote(NS_AUTHOR), headers={
'Accept': 'application/json',
'Content-Type': 'application/json',
'api-secret': hashlib.sha1(NS_SECRET.encode()).hexdigest()
})
if last.status_code == 200:
js = last.json()
return reversed(js)
def main():
js = get_from_nightscout(100)
for x in js:
print(x)
time = parse(x['sysTime'])
sgv = x['sgv']
if __name__ == '__main__':
main()