tp fix
This commit is contained in:
@@ -461,9 +461,10 @@ def handle_add_workouts_team(ws, t, debug=False, **kwargs): # pragma: no cover
|
||||
return 1
|
||||
|
||||
def uploadactivity(access_token, filename, description='',
|
||||
name='Rowsandall.com workout'): # pragma: no cover
|
||||
name='Rowsandall.com workout', workouttype='rowing'): # pragma: no cover
|
||||
|
||||
data_gz = BytesIO()
|
||||
|
||||
try:
|
||||
with open(filename, 'rb') as inF:
|
||||
s = inF.read()
|
||||
@@ -478,12 +479,13 @@ def uploadactivity(access_token, filename, description='',
|
||||
'Authorization': 'Bearer %s' % access_token
|
||||
}
|
||||
|
||||
# Data field is base64 encoded file read from filename
|
||||
data = {
|
||||
"UploadClient": "rowsandall",
|
||||
"Filename": filename,
|
||||
"SetWorkoutPublic": True,
|
||||
"Title": name,
|
||||
"Type": "rowing",
|
||||
"Type": workouttype,
|
||||
"Comment": description,
|
||||
"Data": base64.b64encode(data_gz.getvalue()).decode("ascii")
|
||||
}
|
||||
@@ -495,7 +497,7 @@ def uploadactivity(access_token, filename, description='',
|
||||
if resp.status_code not in (200, 202): # pragma: no cover
|
||||
dologging('tp_export.log',resp.status_code)
|
||||
dologging('tp_export.log',resp.reason)
|
||||
dologging('tp_export.log',json.dumps(data))
|
||||
|
||||
return 0, resp.reason, resp.status_code, headers
|
||||
else:
|
||||
return 1, "ok", 200, resp.headers
|
||||
@@ -564,26 +566,34 @@ def check_tp_workout_id(workout, location, attempts=5, debug=False, **kwargs): #
|
||||
workout.uploadedtotp = tpid
|
||||
record = create_or_update_syncrecord(workout.user, workout, tpid=tpid)
|
||||
workout.save()
|
||||
else:
|
||||
dologging('tp_export.log','failed to get workout id from trainingpeaks')
|
||||
dologging('tp_export.log',response.text)
|
||||
dologging('tp_export.log',status)
|
||||
return 0
|
||||
else:
|
||||
dologging('tp_export.log','failed to get workout id from trainingpeaks')
|
||||
dologging('tp_export.log',response.text)
|
||||
return 0
|
||||
|
||||
return 1
|
||||
|
||||
@app.task
|
||||
def handle_workout_tp_upload(w, thetoken, tcxfilename, debug=False, **kwargs): # pragma: no cover
|
||||
def handle_workout_tp_upload(w, thetoken, tcxfilename, workouttype, debug=False, **kwargs): # pragma: no cover
|
||||
tpid = 0
|
||||
r = w.user
|
||||
dologging('tp_export.log','uploading workout {workoutid} to trainingpeaks for user {id}'.format(id=r.id,workoutid=w.id))
|
||||
|
||||
|
||||
if not tcxfilename:
|
||||
return 0
|
||||
|
||||
res, reason, status_code, headers = uploadactivity(
|
||||
thetoken, tcxfilename,
|
||||
name=w.name
|
||||
name=w.name, workouttype=workouttype,
|
||||
)
|
||||
|
||||
if res == 0:
|
||||
w.tpid = -1
|
||||
w.uploadedtotcx = -1
|
||||
try:
|
||||
os.remove(tcxfilename)
|
||||
except:
|
||||
|
||||
Reference in New Issue
Block a user