2014-11-08 13:35:47 +01:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import getpass
|
|
|
|
import json
|
|
|
|
import logging
|
2020-03-08 20:05:56 +01:00
|
|
|
|
|
|
|
from garminexport.garminclient import GarminClient
|
2014-11-08 13:35:47 +01:00
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO, format="%(asctime)-15s [%(levelname)s] %(message)s")
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-04-07 12:49:44 +02:00
|
|
|
|
2014-11-08 13:35:47 +01:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Export all Garmin Connect activities")
|
|
|
|
# positional args
|
|
|
|
parser.add_argument(
|
|
|
|
"username", metavar="<username>", type=str, help="Account user name.")
|
|
|
|
# optional args
|
|
|
|
parser.add_argument(
|
|
|
|
"--password", type=str, help="Account password.")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
print(args)
|
|
|
|
|
|
|
|
if not args.password:
|
|
|
|
args.password = getpass.getpass("Enter password: ")
|
2020-04-07 12:49:44 +02:00
|
|
|
|
2014-11-08 13:35:47 +01:00
|
|
|
try:
|
|
|
|
with GarminClient(args.username, args.password) as client:
|
|
|
|
log.info("activities:")
|
2015-02-20 09:32:59 +01:00
|
|
|
activity_ids = client.list_activities()
|
2020-04-07 12:49:44 +02:00
|
|
|
log.info("num ids: %d", len(activity_ids))
|
2014-11-08 13:35:47 +01:00
|
|
|
log.info(activity_ids)
|
|
|
|
|
2015-02-20 09:32:59 +01:00
|
|
|
latest_activity, latest_activity_start = activity_ids[0]
|
2014-11-08 13:35:47 +01:00
|
|
|
activity = client.get_activity_summary(latest_activity)
|
2020-04-07 12:49:44 +02:00
|
|
|
log.info("activity id: %s", activity["activity"]["activityId"])
|
|
|
|
log.info("activity name: '%s'", activity["activity"]["activityName"])
|
|
|
|
log.info("activity description: '%s'", activity["activity"]["activityDescription"])
|
2014-11-08 13:35:47 +01:00
|
|
|
log.info(json.dumps(client.get_activity_details(latest_activity), indent=4))
|
|
|
|
log.info(client.get_activity_gpx(latest_activity))
|
|
|
|
except Exception as e:
|
2020-04-07 12:49:44 +02:00
|
|
|
log.error("failed with exception: %s", e)
|
|
|
|
finally:
|
2014-11-08 13:35:47 +01:00
|
|
|
log.info("done")
|