Skip to content

Instantly share code, notes, and snippets.

@mddub
Created January 8, 2016 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mddub/152a0988c786c0704e65 to your computer and use it in GitHub Desktop.
Save mddub/152a0988c786c0704e65 to your computer and use it in GitHub Desktop.
import json
import os
import re
from datetime import datetime
kind = ''
try:
suggested = json.loads(open('enact/enacted.json').read())
kind = 'E'
except IOError:
suggested = json.loads(open('enact/suggested.json').read())
kind = 'S'
recent_bgs = ' '.join([str(g['glucose']) for g in json.loads(open('monitor/glucose.json').read())][:4])
out = ''
time = datetime.fromtimestamp(os.stat('enact/suggested.json').st_mtime).strftime("%I:%M%P")[:-1]
if time.startswith('0'):
time = time[1:]
out += time + ' '
if suggested.get('rate') is not None:
out += 'E '
out += '%sx%sm. ' % (suggested['rate'], suggested.get('duration'))
else:
out += 'S- '
out += recent_bgs + '. '
iob = round(json.loads(open('monitor/iob.json').read())['iob'], 2)
out += '%su. ' % iob
out += suggested['reason']
if suggested.get('snoozeBG'):
out += '. snoozeBG: {}'.format(suggested['snoozeBG'])
out = out.replace('Eventual BG', 'EB')
out = out.replace('Delta', 'De')
out = out.replace('snoozeBG', 'sBG')
out = out.replace('temp', 'tmp')
# round long numbers using re until oref0 fixes "6.333333333333"
out = re.sub('((\d\.\d\d)\d*)', lambda m: m.group(2), out)
print out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment