mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-12 03:34:09 +02:00
Updated Useful import scripts (markdown)
@@ -108,4 +108,36 @@ with open("openScale_garmin_connect_import.csv", "wb") as outfile, open(sys.argv
|
||||
bmi(float(row["weight"])),
|
||||
row["fat"]
|
||||
])
|
||||
```
|
||||
|
||||
## Garmin format --> openScale CSV file
|
||||
|
||||
by antonmosich see https://github.com/oliexdev/openScale/issues/879
|
||||
|
||||
```python
|
||||
#!/usr/bin/python
|
||||
|
||||
import csv
|
||||
import json
|
||||
import datetime
|
||||
import argparse
|
||||
|
||||
OPENSCALE_HEADER = '"biceps","bone","caliper1","caliper2","caliper3","calories","chest","comment","dateTime","fat","hip","lbm","muscle","neck","thigh","visceralFat","waist","water","weight"'
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("input")
|
||||
parser.add_argument("output")
|
||||
args = parser.parse_args()
|
||||
with open(args.input, 'r') as input_file:
|
||||
input_json = json.load(input_file)
|
||||
filtered = [entry for entry in input_json if "weight" in entry]
|
||||
with open(args.output, 'w') as output_file:
|
||||
writer = csv.DictWriter(output_file, OPENSCALE_HEADER.replace('"', '').split(','))
|
||||
output_file.write(f'{OPENSCALE_HEADER}\n')
|
||||
|
||||
for entry in filtered:
|
||||
timestamp = datetime.datetime.fromisoformat(entry['weight']['timestampGMT'].ljust(23,'0'))
|
||||
weight = entry['weight']['weight'] / 1000
|
||||
writer.writerow({'dateTime': timestamp, 'weight': weight})
|
||||
```
|
Reference in New Issue
Block a user