merging changes by dlenski

This commit is contained in:
petergardfjall 2015-08-27 19:18:26 +02:00
parent e25cd38ea6
commit d6cad6736f
4 changed files with 15 additions and 7 deletions

View File

@ -45,10 +45,11 @@ def export_filename(activity, export_format):
:return: The file name to use for the exported activity.
:rtype: str
"""
return "{time}_{id}{suffix}".format(
fn = "{time}_{id}{suffix}".format(
id=activity[0],
time=activity[1].isoformat(),
suffix=format_suffix[export_format])
return fn.replace(':','_') if os.name=='nt' else fn
def need_backup(activities, backup_dir, export_formats=None):

View File

@ -12,7 +12,9 @@ from StringIO import StringIO
import sys
import zipfile
import dateutil
import dateutil.parser
import os.path
from functools import wraps
#
# Note: For more detailed information about the API services
@ -39,6 +41,7 @@ def require_session(client_function):
"""Decorator that is used to annotate :class:`GarminClient`
methods that need an authenticated session before being called.
"""
@wraps(client_function)
def check_session(*args, **kwargs):
client_object = args[0]
if not client_object.session:
@ -270,6 +273,7 @@ class GarminClient(object):
return response.text
@require_session
def get_activity_tcx(self, activity_id):
"""Return a TCX (Training Center XML) representation of a
given activity. If the activity doesn't have a TCX source (for

View File

@ -5,11 +5,12 @@ Connect account and stores it locally on the user's computer.
import argparse
import getpass
from garminexport.garminclient import GarminClient
import garminexport.util
import garminexport.backup
import logging
import os
import sys
import traceback
import dateutil.parser
logging.basicConfig(
level=logging.INFO, format="%(asctime)-15s [%(levelname)s] %(message)s")
@ -36,7 +37,7 @@ if __name__ == "__main__":
parser.add_argument(
"format", metavar="<format>", type=str,
help="Export format (one of: {}).".format(
garminexport.util.export_formats))
garminexport.backup.export_formats))
# optional args
parser.add_argument(
@ -54,10 +55,10 @@ if __name__ == "__main__":
if not args.log_level in LOG_LEVELS:
raise ValueError("Illegal log-level argument: {}".format(
args.log_level))
if not args.format in garminexport.util.export_formats:
if not args.format in garminexport.backup.export_formats:
raise ValueError(
"Uncrecognized export format: '{}'. Must be one of {}".format(
args.format, garminexport.util.export_formats))
args.format, garminexport.backup.export_formats))
logging.root.setLevel(LOG_LEVELS[args.log_level])
try:
@ -68,8 +69,10 @@ if __name__ == "__main__":
args.password = getpass.getpass("Enter password: ")
with GarminClient(args.username, args.password) as client:
log.info("fetching activity {} ...".format(args.activity))
garminexport.util.export_activity(
client, args.activity, args.destination, formats=[args.format])
summary = client.get_activity_summary(args.activity)
starttime = dateutil.parser.parse(summary["activity"]["activitySummary"]["BeginTimestamp"]["value"])
garminexport.backup.download(
client, (args.activity, starttime), 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)

0
upload_activity.py Normal file → Executable file
View File