From efde47cbe4a5c90260d4bed99be51fc10f9d332e Mon Sep 17 00:00:00 2001 From: OliE Date: Sun, 10 Oct 2021 11:14:21 +0200 Subject: [PATCH] Updated Useful import scripts (markdown) --- Useful-import-scripts.md | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/Useful-import-scripts.md b/Useful-import-scripts.md index 13f6a0d..5ed8d7a 100644 --- a/Useful-import-scripts.md +++ b/Useful-import-scripts.md @@ -62,4 +62,50 @@ for w in r: comment = w[5] d = parse(time) writer.writerow([d.strftime('%d.%m.%Y %H:%M'), weight, 0.0, 0.0, 0.0, 0.0, 0.0, comment]) +``` + +## openScale CSV file --> Garmin format + +by jowlo see https://github.com/oliexdev/openScale/issues/777 + +```python +#!/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 + +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", "wb") 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"] + ]) ``` \ No newline at end of file