Cleanup script.
This commit is contained in:
parent
93a4c412c5
commit
f2fd1a0acd
@ -35,27 +35,7 @@ def main():
|
|||||||
'accept': 'application/json',
|
'accept': 'application/json',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
}
|
}
|
||||||
print(secret_hash)
|
#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)
|
|
||||||
|
|
||||||
with open(args.input_file, 'r', newline='') as f:
|
with open(args.input_file, 'r', newline='') as f:
|
||||||
rows = from_csv(f)
|
rows = from_csv(f)
|
||||||
@ -157,13 +137,13 @@ def main():
|
|||||||
if i < len(entries)-1:
|
if i < len(entries)-1:
|
||||||
(entries[i], entries[i+1]) = calculate_entry_delta(entries[i], entries[i+1])
|
(entries[i], entries[i+1]) = calculate_entry_delta(entries[i], entries[i+1])
|
||||||
|
|
||||||
pp.pprint(entries)
|
#pp.pprint(entries)
|
||||||
sys.exit(1)
|
sys.exit(1) # Remove this line to upload!
|
||||||
|
|
||||||
''' Upload data (either treatment or entry) to Nightscout '''
|
''' Upload data (either treatment or entry) to Nightscout '''
|
||||||
actions = {
|
actions = {
|
||||||
#'/treatments': treatments,
|
'/treatments': treatments,
|
||||||
#'/entries': entries,
|
'/entries': entries,
|
||||||
}
|
}
|
||||||
for page, form in actions.items():
|
for page, form in actions.items():
|
||||||
''' Upload data in groups of 100 entries, to avoid timeouts from large datasets '''
|
''' 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:
|
with urllib.request.urlopen(req) as response:
|
||||||
status = response.read().decode('utf-8')
|
status = response.read().decode('utf-8')
|
||||||
status_json = json.loads(status)
|
status_json = json.loads(status)
|
||||||
pp.pprint(status_json)
|
print(status_json)
|
||||||
print('Completed')
|
print('Completed')
|
||||||
except urllib.error.HTTPError as err:
|
except urllib.error.HTTPError as err:
|
||||||
print('{}: URL {}'.format(err, url))
|
print('{}: URL {}'.format(err, url))
|
||||||
|
Loading…
Reference in New Issue
Block a user