#NEWLINE# def DownloadActivityList( self , serviceRecord , exhaustive = False ) : #NEWLINE# #INDENT# '\n        GET List of Activities as JSON File\n\n        URL: http://app.velohero.com/export/workouts/json\n        Parameters:\n        user      = username\n        pass      = password\n        date_from = YYYY-MM-DD\n        date_to   = YYYY-MM-DD\n        ' #NEWLINE# activities = [ ] #NEWLINE# exclusions = [ ] #NEWLINE# discoveredWorkoutIds = [ ] #NEWLINE# params = self . _add_auth_params ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , record = serviceRecord ) #NEWLINE# limitDateFormat = '%Y-%m-%d' #NEWLINE# if exhaustive : #NEWLINE# #INDENT# listEnd = ( datetime . now ( ) + timedelta ( days = 1.5 ) ) #NEWLINE# listStart = datetime ( day = 1 , month = 1 , year = 1980 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# listEnd = ( datetime . now ( ) + timedelta ( days = 1.5 ) ) #NEWLINE# listStart = ( listEnd - timedelta ( days = 20 ) ) #NEWLINE# #UNINDENT# params . update ( { #NEWLINE# #INDENT# 'date_from' : listStart . strftime ( limitDateFormat ) , #NEWLINE# 'date_to' : listEnd . strftime ( limitDateFormat ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# logger . debug ( ( 'Requesting %s to %s' % ( listStart , listEnd ) ) ) #NEWLINE# res = requests . get ( ( self . _urlRoot + '/export/workouts/json' ) , params = params ) #NEWLINE# if ( res . status_code != 200 ) : #NEWLINE# #INDENT# if ( res . status_code == 403 ) : #NEWLINE# #INDENT# raise APIException ( 'Invalid login' , block = True , user_exception = UserException ( UserExceptionType . Authorization , intervention_required = True ) ) #NEWLINE# #UNINDENT# raise APIException ( 'Unable to retrieve activity list' ) #NEWLINE# #UNINDENT# res . raise_for_status ( ) #NEWLINE# try : #NEWLINE# #INDENT# res = res . json ( ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise APIException ( 'Could not decode activity list' ) #NEWLINE# #UNINDENT# if ( 'workouts' not in res ) : #NEWLINE# #INDENT# raise APIException ( 'No activities' ) #NEWLINE# #UNINDENT# for workout in res [ 'workouts' ] : #NEWLINE# #INDENT# workoutId = int ( workout [ 'id' ] ) #NEWLINE# if ( workoutId in discoveredWorkoutIds ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# discoveredWorkoutIds . append ( workoutId ) #NEWLINE# if ( workout [ 'file' ] is not '1' ) : #NEWLINE# #INDENT# logger . debug ( ( ( 'Skip workout with ID: ' + str ( workoutId ) ) + ' (no file)' ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# activity = UploadedActivity ( ) #NEWLINE# logger . debug ( ( 'Workout ID: ' + str ( workoutId ) ) ) #NEWLINE# duration = self . _durationToSeconds ( workout [ 'dur_time' ] ) #NEWLINE# activity . Stats . TimerTime = ActivityStatistic ( ActivityStatisticUnit . Seconds , value = duration ) #NEWLINE# startTimeStr = ( ( workout [ 'date_ymd' ] + ' ' ) + workout [ 'start_time' ] ) #NEWLINE# activity . StartTime = self . _parseDateTime ( startTimeStr ) #NEWLINE# activity . EndTime = ( self . _parseDateTime ( startTimeStr ) + timedelta ( seconds = duration ) ) #NEWLINE# if ( workout [ 'sport_id' ] in self . _reverseActivityMappings ) : #NEWLINE# #INDENT# activity . Type = self . _reverseActivityMappings [ self [ 'sport_id' ] ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# activity . Type = ActivityType . Other #NEWLINE# #UNINDENT# activity . Stats . Distance = ActivityStatistic ( ActivityStatisticUnit . Kilometers , value = float ( workout [ 'dist_km' ] ) ) #NEWLINE# activity . Private = ( workout [ 'hide' ] == '1' ) #NEWLINE# activity . ServiceData = { #NEWLINE# #INDENT# 'workoutId' : workoutId , #NEWLINE# #UNINDENT# } #NEWLINE# activity . CalculateUID ( ) #NEWLINE# activities . append ( activity ) #NEWLINE# #UNINDENT# return ( activities , exclusions )