summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2017-01-26 14:09:16 +0000
committerAndrew Cady <d@jerkface.net>2017-01-26 14:09:16 +0000
commite1bb96f519c0492319167700673313aa1f61595c (patch)
treeb0a8014133d45f3bd935c215e7bd29213539b91c
parent5b79e4eb51a6140c3747ee135af36b4c2c285484 (diff)
dexcom_dumper: fix EGVRecord JSON output when .is_special==True
-rw-r--r--dexcom_reader/dexcom_dumper.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/dexcom_reader/dexcom_dumper.py b/dexcom_reader/dexcom_dumper.py
index c531dfc..8a0c0d6 100644
--- a/dexcom_reader/dexcom_dumper.py
+++ b/dexcom_reader/dexcom_dumper.py
@@ -2,13 +2,13 @@ import constants
2import readdata 2import readdata
3import sys 3import sys
4import json 4import json
5import requests 5# import requests # As this takes SEVEN SECONDS, it's delayed until needed
6from pytz import UTC
7from sys import stdout, stderr 6from sys import stdout, stderr
8from datetime import timedelta, datetime 7from datetime import timedelta, datetime
9from time import sleep 8from time import sleep
10from itertools import islice, takewhile 9from itertools import islice, takewhile
11from database_records import GenericTimestampedRecord 10from database_records import GenericTimestampedRecord, EGVRecord
11# from pytz import UTC # Since the dependency is external, don't import unless needed
12 12
13from optparse import OptionParser 13from optparse import OptionParser
14 14
@@ -39,6 +39,8 @@ HOST = options.host
39 39
40if command is 'dump_cgm' and options.num_records is None and not options.hours: 40if command is 'dump_cgm' and options.num_records is None and not options.hours:
41 options.hours = 2 41 options.hours = 2
42if options.num_records <= 0:
43 options.num_records = None
42 44
43def get_dexcom_reader(): 45def get_dexcom_reader():
44 if options.g5: 46 if options.g5:
@@ -127,15 +129,17 @@ def sleep_verbose(n):
127 sleep(n) 129 sleep(n)
128 130
129def POST(path, json_str): 131def POST(path, json_str):
132 resp = None
130 try: 133 try:
134 import requests
131 resp = requests.post(HOST + path, data=json_str, 135 resp = requests.post(HOST + path, data=json_str,
132 headers={'Content-type': 136 headers={'Content-type': 'application/json'})
133 'application/json'})
134 print_verbose(resp.text)
135 resp.raise_for_status() 137 resp.raise_for_status()
136 return True 138 return True
137 except: 139 except:
138 print_verbose(sys.exc_info()) 140 print_verbose(sys.exc_info())
141 if resp:
142 print_verbose(resp.text)
139 return False 143 return False
140 144
141def send_ping(now): 145def send_ping(now):
@@ -192,6 +196,7 @@ class JSON_Time(json.JSONEncoder):
192 def default(self, o): 196 def default(self, o):
193 if isinstance(o, datetime): 197 if isinstance(o, datetime):
194 if o.tzinfo is None: 198 if o.tzinfo is None:
199 from pytz import UTC
195 return o.replace(tzinfo=UTC).isoformat() 200 return o.replace(tzinfo=UTC).isoformat()
196 else: 201 else:
197 return o.isoformat() 202 return o.isoformat()
@@ -200,7 +205,12 @@ class JSON_Time(json.JSONEncoder):
200 205
201class JSON_CGM(JSON_Time): 206class JSON_CGM(JSON_Time):
202 def default(self, o): 207 def default(self, o):
203 if isinstance(o, GenericTimestampedRecord): 208 if isinstance(o, EGVRecord) and o.is_special:
209 op={}
210 for k in o.BASE_FIELDS + ['glucose_special_meaning']:
211 op[k] = getattr(o, k)
212 return op
213 elif isinstance(o, GenericTimestampedRecord):
204 op={} 214 op={}
205 for k in o.BASE_FIELDS + o.FIELDS: 215 for k in o.BASE_FIELDS + o.FIELDS:
206 op[k] = getattr(o, k) 216 op[k] = getattr(o, k)