diff --git a/Useful-import-scripts.md b/Useful-import-scripts.md index ed77f51..10a78ba 100644 --- a/Useful-import-scripts.md +++ b/Useful-import-scripts.md @@ -140,4 +140,40 @@ if __name__ == '__main__': timestamp = datetime.datetime.fromisoformat(entry['weight']['timestampGMT'].ljust(23,'0')) weight = entry['weight']['weight'] / 1000 writer.writerow({'dateTime': timestamp, 'weight': weight}) -``` \ No newline at end of file +``` + +## Google Fit Takeout --> openScale CSV file + +by sainigma see https://github.com/oliexdev/openScale/issues/1040 + +```python +#!/usr/bin/env python +import csv +from dateutil.parser import parse + +with open('Daily activity metrics.csv', newline='') as input_csv: + csv_reader = csv.reader(input_csv, delimiter=',') + + rows = [] + + for row in csv_reader: + rows.append(row) + + headers = rows[0] + data = rows[1:] + + date_idx = headers.index('Date') + weight_idx = headers.index('Average weight (kg)') + + with open('openscale_data.csv', 'w', newline='', encoding='utf-8') as output_csv: + output_writer = csv.writer(output_csv, delimiter=',') + + output_writer.writerow(["dateTime", "weight"]) + + for fragment in data: + date = fragment[date_idx] + weight = fragment[weight_idx] + + if (weight and date): + output_writer.writerow([parse(date).strftime('%d.%m.%Y 08:00'), round(float(weight), 2)]) +```