merging changes by dlenski
This commit is contained in:
		
							parent
							
								
									e25cd38ea6
								
							
						
					
					
						commit
						d6cad6736f
					
				@ -45,10 +45,11 @@ def export_filename(activity, export_format):
 | 
				
			|||||||
    :return: The file name to use for the exported activity.
 | 
					    :return: The file name to use for the exported activity.
 | 
				
			||||||
    :rtype: str
 | 
					    :rtype: str
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    return "{time}_{id}{suffix}".format(
 | 
					    fn = "{time}_{id}{suffix}".format(
 | 
				
			||||||
        id=activity[0],
 | 
					        id=activity[0],
 | 
				
			||||||
        time=activity[1].isoformat(), 
 | 
					        time=activity[1].isoformat(), 
 | 
				
			||||||
        suffix=format_suffix[export_format])   
 | 
					        suffix=format_suffix[export_format])   
 | 
				
			||||||
 | 
					    return fn.replace(':','_') if os.name=='nt' else fn
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def need_backup(activities, backup_dir, export_formats=None):
 | 
					def need_backup(activities, backup_dir, export_formats=None):
 | 
				
			||||||
 | 
				
			|||||||
@ -12,7 +12,9 @@ from StringIO import StringIO
 | 
				
			|||||||
import sys
 | 
					import sys
 | 
				
			||||||
import zipfile
 | 
					import zipfile
 | 
				
			||||||
import dateutil
 | 
					import dateutil
 | 
				
			||||||
 | 
					import dateutil.parser
 | 
				
			||||||
import os.path
 | 
					import os.path
 | 
				
			||||||
 | 
					from functools import wraps
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# Note: For more detailed information about the API services
 | 
					# 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`
 | 
					    """Decorator that is used to annotate :class:`GarminClient`
 | 
				
			||||||
    methods that need an authenticated session before being called.
 | 
					    methods that need an authenticated session before being called.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					    @wraps(client_function)
 | 
				
			||||||
    def check_session(*args, **kwargs):
 | 
					    def check_session(*args, **kwargs):
 | 
				
			||||||
        client_object = args[0]
 | 
					        client_object = args[0]
 | 
				
			||||||
        if not client_object.session:
 | 
					        if not client_object.session:
 | 
				
			||||||
@ -270,6 +273,7 @@ class GarminClient(object):
 | 
				
			|||||||
        return response.text
 | 
					        return response.text
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @require_session
 | 
				
			||||||
    def get_activity_tcx(self, activity_id):
 | 
					    def get_activity_tcx(self, activity_id):
 | 
				
			||||||
        """Return a TCX (Training Center XML) representation of a
 | 
					        """Return a TCX (Training Center XML) representation of a
 | 
				
			||||||
        given activity. If the activity doesn't have a TCX source (for
 | 
					        given activity. If the activity doesn't have a TCX source (for
 | 
				
			||||||
 | 
				
			|||||||
@ -5,11 +5,12 @@ Connect account and stores it locally on the user's computer.
 | 
				
			|||||||
import argparse
 | 
					import argparse
 | 
				
			||||||
import getpass
 | 
					import getpass
 | 
				
			||||||
from garminexport.garminclient import GarminClient
 | 
					from garminexport.garminclient import GarminClient
 | 
				
			||||||
import garminexport.util
 | 
					import garminexport.backup
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import traceback
 | 
					import traceback
 | 
				
			||||||
 | 
					import dateutil.parser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
logging.basicConfig(
 | 
					logging.basicConfig(
 | 
				
			||||||
    level=logging.INFO, format="%(asctime)-15s [%(levelname)s] %(message)s")
 | 
					    level=logging.INFO, format="%(asctime)-15s [%(levelname)s] %(message)s")
 | 
				
			||||||
@ -36,7 +37,7 @@ if __name__ == "__main__":
 | 
				
			|||||||
    parser.add_argument(
 | 
					    parser.add_argument(
 | 
				
			||||||
        "format", metavar="<format>", type=str,
 | 
					        "format", metavar="<format>", type=str,
 | 
				
			||||||
        help="Export format (one of: {}).".format(
 | 
					        help="Export format (one of: {}).".format(
 | 
				
			||||||
            garminexport.util.export_formats))
 | 
					            garminexport.backup.export_formats))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # optional args
 | 
					    # optional args
 | 
				
			||||||
    parser.add_argument(
 | 
					    parser.add_argument(
 | 
				
			||||||
@ -54,10 +55,10 @@ if __name__ == "__main__":
 | 
				
			|||||||
    if not args.log_level in LOG_LEVELS:
 | 
					    if not args.log_level in LOG_LEVELS:
 | 
				
			||||||
        raise ValueError("Illegal log-level argument: {}".format(
 | 
					        raise ValueError("Illegal log-level argument: {}".format(
 | 
				
			||||||
            args.log_level))
 | 
					            args.log_level))
 | 
				
			||||||
    if not args.format in garminexport.util.export_formats:
 | 
					    if not args.format in garminexport.backup.export_formats:
 | 
				
			||||||
        raise ValueError(
 | 
					        raise ValueError(
 | 
				
			||||||
            "Uncrecognized export format: '{}'. Must be one of {}".format(
 | 
					            "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])
 | 
					    logging.root.setLevel(LOG_LEVELS[args.log_level])
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
@ -68,8 +69,10 @@ if __name__ == "__main__":
 | 
				
			|||||||
            args.password = getpass.getpass("Enter password: ")
 | 
					            args.password = getpass.getpass("Enter password: ")
 | 
				
			||||||
        with GarminClient(args.username, args.password) as client:
 | 
					        with GarminClient(args.username, args.password) as client:
 | 
				
			||||||
            log.info("fetching activity {} ...".format(args.activity))
 | 
					            log.info("fetching activity {} ...".format(args.activity))
 | 
				
			||||||
            garminexport.util.export_activity(
 | 
					            summary = client.get_activity_summary(args.activity)
 | 
				
			||||||
                client, args.activity, args.destination, formats=[args.format])
 | 
					            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:
 | 
					    except Exception as e:
 | 
				
			||||||
        exc_type, exc_value, exc_traceback = sys.exc_info()
 | 
					        exc_type, exc_value, exc_traceback = sys.exc_info()
 | 
				
			||||||
        log.error(u"failed with exception: %s", e)
 | 
					        log.error(u"failed with exception: %s", e)
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										0
									
								
								upload_activity.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								upload_activity.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
		Loading…
	
		Reference in New Issue
	
	Block a user