diff options
author | Andrew Cady <d@jerkface.net> | 2017-01-26 14:09:16 +0000 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2017-01-26 14:09:16 +0000 |
commit | e1bb96f519c0492319167700673313aa1f61595c (patch) | |
tree | b0a8014133d45f3bd935c215e7bd29213539b91c | |
parent | 5b79e4eb51a6140c3747ee135af36b4c2c285484 (diff) |
dexcom_dumper: fix EGVRecord JSON output when .is_special==True
-rw-r--r-- | dexcom_reader/dexcom_dumper.py | 24 |
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 | |||
2 | import readdata | 2 | import readdata |
3 | import sys | 3 | import sys |
4 | import json | 4 | import json |
5 | import requests | 5 | # import requests # As this takes SEVEN SECONDS, it's delayed until needed |
6 | from pytz import UTC | ||
7 | from sys import stdout, stderr | 6 | from sys import stdout, stderr |
8 | from datetime import timedelta, datetime | 7 | from datetime import timedelta, datetime |
9 | from time import sleep | 8 | from time import sleep |
10 | from itertools import islice, takewhile | 9 | from itertools import islice, takewhile |
11 | from database_records import GenericTimestampedRecord | 10 | from database_records import GenericTimestampedRecord, EGVRecord |
11 | # from pytz import UTC # Since the dependency is external, don't import unless needed | ||
12 | 12 | ||
13 | from optparse import OptionParser | 13 | from optparse import OptionParser |
14 | 14 | ||
@@ -39,6 +39,8 @@ HOST = options.host | |||
39 | 39 | ||
40 | if command is 'dump_cgm' and options.num_records is None and not options.hours: | 40 | if command is 'dump_cgm' and options.num_records is None and not options.hours: |
41 | options.hours = 2 | 41 | options.hours = 2 |
42 | if options.num_records <= 0: | ||
43 | options.num_records = None | ||
42 | 44 | ||
43 | def get_dexcom_reader(): | 45 | def 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 | ||
129 | def POST(path, json_str): | 131 | def 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 | ||
141 | def send_ping(now): | 145 | def 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 | ||
201 | class JSON_CGM(JSON_Time): | 206 | class 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) |