1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-10 18:54:20 +02:00

Updated Useful import scripts (markdown)

OliE
2024-05-20 09:59:51 +02:00
parent 5c76dd78ff
commit 18abf04b40

@@ -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})
```
```
## 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)])
```