-
-
Save mddub/152a0988c786c0704e65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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