Last active
December 14, 2021 17:58
-
-
Save dylan-lawrence/8712fbde5b4c574b69848988d87b3c7a to your computer and use it in GitHub Desktop.
A converter to convert from USA LibreView output to EU LibreView output
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
#A converter for LibreView exported data, can convert from European or USA output formats | |
import argparse | |
#TODO Setup argparse for changing conversion | |
#2018-13-1 | |
#Currently this script accepts a USA input from argument 1 and converts it to European format. | |
import sys | |
def us_to_eu_date(string): | |
string = string.split() | |
h=0 | |
m=0 | |
(h,m)=string[1].split(':') | |
if string[2]=='PM': | |
if int(h) > 11: h=0 | |
h=str(int(h)+12) | |
if string[2]=='AM': | |
if h=='12': h='00' | |
elif h=='10' or h=='11': pass | |
else: h='0'+h | |
date=string[0].split('-') | |
date=date[2]+'/'+date[0]+'/'+date[1] | |
return date + ' ' + h+':'+m | |
def us_to_eu(fpath): | |
lines = [] | |
with open(fpath,'r') as f: | |
lines = f.readlines() | |
l1 = lines[0].rstrip('\n').split(',') | |
l2 = lines[1].rstrip('\n').split(',') | |
lines = lines[2::] | |
name = l1[-2] | |
with open('converted.txt','w') as f: | |
f.write(name+'\n') | |
eu_header = "ID Time\tRecord Type\tHistoric Glucose (mg/dL)\tScan Glucose (mg/dL)\tNon-numeric Rapid-Acting Insulin\tRapid-Acting Insulin (units)\tNon-numeric Food Carbohydrates (grams)\tNon-numeric Long-Acting Insulin\tLong-Acting Insulin (units)\tNotes\tStrip Glucose (mg/dL)\tKetone (mmol/L)\tMeal Insulin (units)\tCorrection Insulin (units)\tUser Change Insulin (units)\tPrevious Time\tUpdated Time" | |
f.write(eu_header+'\n') | |
for line in lines: | |
line = line.split(',') | |
line = line[0]+'\t'+us_to_eu_date(line[2])+'\t0\t'+line[3].rstrip('\n') | |
f.write(line+'\n') | |
return | |
if __name__ == '__main__': | |
fpath = sys.argv[1] | |
us_to_eu(fpath) |
Revision 4: Actually fixed time issues
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Revision 2: Fixed issue where 12:xx PM was converting to 24:xx instead of 12:xx