#NEWLINE# def UploadActivity( self , serviceRecord , activity ) : #NEWLINE# #INDENT# '\n        POST a Multipart-Encoded File\n        \n        URL: http://app.velohero.com/upload/file\n        Parameters:\n        user = username\n        pass = password\n        view = json\n        file = multipart-encodes file (fit, tcx, pwx, gpx, srm, hrm...)\n        \n        Maximum file size per file is 16 MB.\n        ' #NEWLINE# has_location = has_distance = has_speed = False #NEWLINE# for lap in activity . Laps : #NEWLINE# #INDENT# for wp in lap . Waypoints : #NEWLINE# #INDENT# if ( wp . Location and wp . Location . Latitude and wp . Location . Longitude ) : #NEWLINE# #INDENT# has_location = True #NEWLINE# #UNINDENT# if wp . Distance : #NEWLINE# #INDENT# has_distance = True #NEWLINE# #UNINDENT# if activity . Speed : #NEWLINE# #INDENT# has_speed = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( has_location and has_distance and has_speed ) : #NEWLINE# #INDENT# format = 'fit' #NEWLINE# data = FITIO . Dump ( activity ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( has_location and has_distance ) : #NEWLINE# #INDENT# format = 'tcx' #NEWLINE# data = TCXIO . Dump ( activity ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if has_location : #NEWLINE# #INDENT# format = 'gpx' #NEWLINE# data = GPXIO . Dump ( activity ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# format = 'fit' #NEWLINE# data = FITIO . Dump ( activity ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# files = { #NEWLINE# #INDENT# 'file' : ( ( ( ( ( ( 'tap-sync-' + str ( os . getpid ( ) ) ) + '-' ) + activity . UID ) + '.' ) + format ) , data ) , #NEWLINE# #UNINDENT# } #NEWLINE# params = self . _add_auth_params ( { #NEWLINE# #INDENT# 'view' : 'json' , #NEWLINE# #UNINDENT# } , record = serviceRecord ) #NEWLINE# res = requests . post ( ( self . _urlRoot + '/upload/file' ) , files = files , 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 upload activity' ) #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 ( 'error' in res ) : #NEWLINE# #INDENT# raise APIException ( res [ 'error' ] ) #NEWLINE# #UNINDENT# if ( 'id' in res ) : #NEWLINE# #INDENT# workoutId = res [ 'id' ] #NEWLINE# params = self . _add_auth_params ( { #NEWLINE# #INDENT# 'workout_date' : activity . StartTime . strftime ( '%Y-%m-%d' ) , #NEWLINE# 'workout_start_time' : activity . StartTime . strftime ( '%H:%M:%S' ) , #NEWLINE# 'workout_comment' : activity . Notes , #NEWLINE# 'sport_id' : self . _activityMappings [ activity . Type ] , #NEWLINE# 'workout_hide' : ( 'yes' if activity . Private else 'no' ) , #NEWLINE# #UNINDENT# } , record = serviceRecord ) #NEWLINE# res = requests . get ( ( self . _urlRoot + '/workouts/change/{}' . format ( workoutId ) ) , params = params ) #NEWLINE# if ( res . status_code != 200 ) : #NEWLINE# #INDENT# if ( res . status_code == 403 ) : #NEWLINE# #INDENT# raise APIException ( 'No authorization to change activity with workout ID: {}' . format ( workoutId ) , block = True , user_exception = UserException ( UserExceptionType . Authorization , intervention_required = True ) ) #NEWLINE# #UNINDENT# raise APIException ( 'Unable to change activity with workout ID: {}' . format ( workoutId ) ) #NEWLINE# #UNINDENT# return workoutId