From f2fd1a0acda757691edf5b85f47237d175a3672d Mon Sep 17 00:00:00 2001 From: tim Date: Thu, 10 May 2018 22:53:21 +0200 Subject: [PATCH] Cleanup script. --- freestyle_to_nightscout.py | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/freestyle_to_nightscout.py b/freestyle_to_nightscout.py index f64560d..8455ea9 100644 --- a/freestyle_to_nightscout.py +++ b/freestyle_to_nightscout.py @@ -35,27 +35,7 @@ def main(): 'accept': 'application/json', 'Content-Type': 'application/json', } - print(secret_hash) - - - for page in ( ): - #for page in ( '/status.json', '/entries.json', '/treatments.json' ): - #for page in ( '/entries.json?count=500', '/treatments.json?count=100' ): - url = args.server + page - #pp.pprint(url) - #pp.pprint(headers) - try: - req = urllib.request.Request(url, headers = headers) - with urllib.request.urlopen(req) as response: - status = response.read().decode('utf-8') - status_json = json.loads(status) - if re.match(page, '^/entries') is not None: - status_json.sort(key=lambda e: e['date']) - pp.pprint(status_json) - except urllib.error.HTTPError as err: - print('{}: URL {}'.format(err, url)) - - #sys.exit(1) + #print(secret_hash) with open(args.input_file, 'r', newline='') as f: rows = from_csv(f) @@ -157,13 +137,13 @@ def main(): if i < len(entries)-1: (entries[i], entries[i+1]) = calculate_entry_delta(entries[i], entries[i+1]) - pp.pprint(entries) - sys.exit(1) + #pp.pprint(entries) + sys.exit(1) # Remove this line to upload! ''' Upload data (either treatment or entry) to Nightscout ''' actions = { - #'/treatments': treatments, - #'/entries': entries, + '/treatments': treatments, + '/entries': entries, } for page, form in actions.items(): ''' Upload data in groups of 100 entries, to avoid timeouts from large datasets ''' @@ -176,7 +156,7 @@ def main(): with urllib.request.urlopen(req) as response: status = response.read().decode('utf-8') status_json = json.loads(status) - pp.pprint(status_json) + print(status_json) print('Completed') except urllib.error.HTTPError as err: print('{}: URL {}'.format(err, url))