Skip to content

Instantly share code, notes, and snippets.

@jaimet
Forked from dylan-lawrence/libreconverter.py
Created December 14, 2021 17:58
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 jaimet/aae01a4e5bc489f6f0bd0782c01d1a84 to your computer and use it in GitHub Desktop.
Save jaimet/aae01a4e5bc489f6f0bd0782c01d1a84 to your computer and use it in GitHub Desktop.
A converter to convert from USA LibreView output to EU LibreView output
#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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment