Private
Public Access
1
0
This commit is contained in:
2025-01-20 21:21:11 +01:00
parent 10b1273adf
commit fc925e199f
3 changed files with 22 additions and 10 deletions

View File

@@ -15,7 +15,7 @@ from rowingdata import rowingdata
from rowers.rower_rules import is_workout_user from rowers.rower_rules import is_workout_user
import time import time
from django_rq import job from django_rq import job
from rowers.mytypes import tpmapping from rowers.mytypes import tpmapping, tcxmapping
from rowers.tasks import check_tp_workout_id, handle_workout_tp_upload from rowers.tasks import check_tp_workout_id, handle_workout_tp_upload
@@ -68,7 +68,8 @@ class TPIntegration(SyncIntegration):
newnotes = 'from '+w.workoutsource+' via rowsandall.com' newnotes = 'from '+w.workoutsource+' via rowsandall.com'
try: try:
row.exporttotcx(tcxfilename, notes=newnotes, sport=tpmapping[w.workouttype]) #row.exporttotcx(tcxfilename, notes=newnotes, sport=tcxmapping[w.workouttype])
row.exporttotcx(tcxfilename, notes=newnotes, sport=None)
except KeyError: except KeyError:
row.exporttotcx(tcxfilename, notes=newnotes, sport='other') row.exporttotcx(tcxfilename, notes=newnotes, sport='other')
@@ -83,7 +84,8 @@ class TPIntegration(SyncIntegration):
handle_workout_tp_upload, handle_workout_tp_upload,
workout, workout,
thetoken, thetoken,
tcxfilename tcxfilename,
tpmapping[workout.workouttype]
) )
return job.id return job.id

View File

@@ -461,9 +461,10 @@ def handle_add_workouts_team(ws, t, debug=False, **kwargs): # pragma: no cover
return 1 return 1
def uploadactivity(access_token, filename, description='', 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() data_gz = BytesIO()
try: try:
with open(filename, 'rb') as inF: with open(filename, 'rb') as inF:
s = inF.read() s = inF.read()
@@ -478,12 +479,13 @@ def uploadactivity(access_token, filename, description='',
'Authorization': 'Bearer %s' % access_token 'Authorization': 'Bearer %s' % access_token
} }
# Data field is base64 encoded file read from filename
data = { data = {
"UploadClient": "rowsandall", "UploadClient": "rowsandall",
"Filename": filename, "Filename": filename,
"SetWorkoutPublic": True, "SetWorkoutPublic": True,
"Title": name, "Title": name,
"Type": "rowing", "Type": workouttype,
"Comment": description, "Comment": description,
"Data": base64.b64encode(data_gz.getvalue()).decode("ascii") "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 if resp.status_code not in (200, 202): # pragma: no cover
dologging('tp_export.log',resp.status_code) dologging('tp_export.log',resp.status_code)
dologging('tp_export.log',resp.reason) dologging('tp_export.log',resp.reason)
dologging('tp_export.log',json.dumps(data))
return 0, resp.reason, resp.status_code, headers return 0, resp.reason, resp.status_code, headers
else: else:
return 1, "ok", 200, resp.headers 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 workout.uploadedtotp = tpid
record = create_or_update_syncrecord(workout.user, workout, tpid=tpid) record = create_or_update_syncrecord(workout.user, workout, tpid=tpid)
workout.save() 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 return 1
@app.task @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 tpid = 0
r = w.user r = w.user
dologging('tp_export.log','uploading workout {workoutid} to trainingpeaks for user {id}'.format(id=r.id,workoutid=w.id)) dologging('tp_export.log','uploading workout {workoutid} to trainingpeaks for user {id}'.format(id=r.id,workoutid=w.id))
if not tcxfilename: if not tcxfilename:
return 0 return 0
res, reason, status_code, headers = uploadactivity( res, reason, status_code, headers = uploadactivity(
thetoken, tcxfilename, thetoken, tcxfilename,
name=w.name name=w.name, workouttype=workouttype,
) )
if res == 0: if res == 0:
w.tpid = -1 w.uploadedtotcx = -1
try: try:
os.remove(tcxfilename) os.remove(tcxfilename)
except: except:

Binary file not shown.