Skip to content

Import script for Garmin files #879

@antonmosich

Description

@antonmosich

When going to this page you can use your GDPR right to extraction of you data to get a copy of all collected data. I wrote a script which extracts weight measurements from the user_biometrics.json file you will receive (among others).

#!/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})

Should someone be able to provide his/her file containing more detailed measurements (body fat etc.) I would adapt my script accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementIndicates new feature requests

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions