Last active
April 20, 2024 08:18
-
-
Save jowlo/ec3c2c1c78ea3fab4c15f1f6fd3952ac 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
#!/usr/bin/env python | |
""" | |
Simple script to transform openscale csv export files to a format accepted by garmin connect at | |
https://connect.garmin.com/modern/import-data | |
Note: When importing the language needs to be set to English, otherwise the import fails. | |
Set everything to metric units and to YYYY-MM-DD date format. | |
If you want to compute BMI for the file give your height (im meters) as second parameter. | |
""" | |
import sys | |
import csv | |
from dateutil.parser import parse | |
from __future__ import print_function | |
if len(sys.argv) < 2: | |
print("Missing file to transform\n") | |
sys.exit(1) | |
bmi = lambda size: 0; | |
if len(sys.argv) == 3: | |
bmi = lambda weight: weight/(float(sys.argv[2])**2) | |
with open("openScale_garmin_connect_import.csv", "w") as outfile, open(sys.argv[1], "r") as infile: | |
reader = csv.DictReader(infile, delimiter=",") | |
writer = csv.writer(outfile, delimiter=",") | |
outfile.write("Body\n") | |
outfile.write("Date,Weight,BMI,Fat\n") | |
for row in reader: | |
writer.writerow([ | |
parse(row["dateTime"]).strftime('%Y-%m-%d'), | |
row["weight"], | |
bmi(float(row["weight"])), | |
row["fat"] | |
]) |
Please change writing mode to "w" only and not "write binary" or line 31 and 32 are not working
Thanks, yeah! I think I wrote this for python 2 because everything on the openscale import/export wiki page wiki was for python 2 only. Should be fine with python2 and python3 now.
It does :-)
Thank you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the ( ) around "" is missing