updated get_activity code to make use of a Retryer

This commit is contained in:
petergardfjall 2018-08-30 19:58:53 +02:00
parent 01a08e14ab
commit ed32d335ad

View File

@ -3,9 +3,13 @@
Connect account and stores it locally on the user's computer.
"""
import argparse
from datetime import timedelta
import getpass
from garminexport.garminclient import GarminClient
import garminexport.backup
from garminexport.retryer import (
Retryer, ExponentialBackoffDelayStrategy, MaxRetriesStopStrategy)
import json
import logging
import os
import sys
@ -70,11 +74,17 @@ if __name__ == "__main__":
with GarminClient(args.username, args.password) as client:
log.info("fetching activity {} ...".format(args.activity))
summary = client.get_activity_summary(args.activity)
starttime = dateutil.parser.parse(summary["activity"]["activitySummary"]["BeginTimestamp"]["value"])
# set up a retryer that will handle retries of failed activity
# downloads
retryer = Retryer(
delay_strategy=ExponentialBackoffDelayStrategy(
initial_delay=timedelta(seconds=1)),
stop_strategy=MaxRetriesStopStrategy(5))
starttime = dateutil.parser.parse(summary["summaryDTO"]["startTimeGMT"])
garminexport.backup.download(
client, (args.activity, starttime), args.destination, export_formats=[args.format])
client, (args.activity, starttime), retryer, args.destination, export_formats=[args.format])
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
log.error(u"failed with exception: %s", e)
raise