mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-10 18:54:20 +02:00
Updated Useful import scripts (markdown)
@@ -198,3 +198,62 @@ with open('Daily activity metrics.csv', newline='') as input_csv:
|
||||
if (weight and date):
|
||||
output_writer.writerow([parse(date).strftime('%d.%m.%Y 08:00'), round(float(weight), 2)])
|
||||
```
|
||||
|
||||
## Apple Health --> openScale CSV file
|
||||
|
||||
by MoralCode see https://github.com/oliexdev/openScale/issues/731
|
||||
|
||||
```python
|
||||
#!/usr/bin/python
|
||||
|
||||
# Usage: first run your apple health export through the scripts as documented in https://github.com/markwk/qs_ledger/tree/master/apple_health
|
||||
# then run this script using the BodyMass.csv from this process to get an OpenScale csv
|
||||
|
||||
import argparse
|
||||
import csv
|
||||
import datetime
|
||||
from dateutil.parser import parse as parsedate
|
||||
|
||||
OPENSCALE_HEADER = '"biceps","bone","caliper1","caliper2","caliper3","calories","chest","comment","dateTime","fat","hip","lbm","muscle","neck","thigh","visceralFat","waist","water","weight"'
|
||||
OPENSCALE_HEADER = OPENSCALE_HEADER.replace('"', '')
|
||||
|
||||
_APPLE_QUANTIFIEDSELF_BODYMASS_HEADER = 'sourceName,sourceVersion,device,type,unit,creationDate,startDate,endDate,value'
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('apple_bodymass_csv_file_path')
|
||||
parser.add_argument('output_path')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
with open(args.apple_bodymass_csv_file_path, 'r') as inp:
|
||||
reader = csv.DictReader(inp)
|
||||
with open(args.output_path, 'w') as outp:
|
||||
writer = csv.DictWriter(outp, OPENSCALE_HEADER.split(','))
|
||||
# outp.write(f'{OPENSCALE_HEADER}\n')
|
||||
writer.writeheader()
|
||||
|
||||
for line in reader:
|
||||
creationDate = line['creationDate']
|
||||
output_date = parsedate(creationDate).strftime('%Y-%m-%d %H:%M')
|
||||
weight = float(line['value'])
|
||||
if line['unit'] == 'lb':
|
||||
# convert to KG
|
||||
weight = weight / 2.2
|
||||
|
||||
comment = "Imported from Apple Health export. Data originally from "
|
||||
appname = line["sourceName"]
|
||||
# make the apple health app name a little more obvious. by default its just "health"
|
||||
if appname == "Health":
|
||||
appname = "Apple Health"
|
||||
comment += appname + " app"
|
||||
appversion = line["sourceVersion"]
|
||||
if appversion != "":
|
||||
comment += " version " + appversion
|
||||
|
||||
writer.writerow({
|
||||
'dateTime': output_date,
|
||||
'weight': "{:.2f}".format(weight),
|
||||
'comment': comment
|
||||
})
|
||||
```
|
Reference in New Issue
Block a user