Private
Public Access
1
0

fixing sync wup/cd with icu

This commit is contained in:
2025-03-02 13:42:26 +01:00
parent 02a774bcf8
commit 7ee8836335
6 changed files with 75 additions and 8 deletions

View File

@@ -220,15 +220,23 @@ class IntervalsIntegration(SyncIntegration):
thetype = mytypes.intervalsmapping[workout.workouttype]
jsondict = {'type': thetype}
subtype = workout.sub_type
if subtype:
jsondict['sub_type'] = subtype
if subtype == "Warming Up":
jsondict['sub_type'] = "WARMUP"
elif subtype == "Cooling Down":
jsondict['sub_type'] = "COOLDOWN"
elif subtype == "Commute":
jsondict['commute'] = True
jsondict['sub_type'] = "COMMUTE"
else:
jsondict['sub_type'] = "NONE"
if workout.rpe is not None and workout.rpe > 0:
jsondict['icu_rpe'] = workout.rpe
jsondict['icu_rpe'] = workout.rpe
jsondict['commute'] = workout.is_commute
if workout.plannedsession:
jsondict['paired_event_id'] = workout.plannedsession.intervals_icu_id
response = requests.put(url, headers=headers, json=jsondict)
if response.status_code not in [200, 201]:
@@ -322,6 +330,14 @@ class IntervalsIntegration(SyncIntegration):
dologging('intervals.icu.log', response.text)
return 0
subtypemapping = {
'WARMUP': 'Warming Up',
'COOLDOWN': 'Cooling Down',
'COMMUTE': 'Commute',
'NONE': None,
'RACE': 'Race'
}
data = response.json()
ws = Workout.objects.filter(uploadedtointervals=id)
@@ -338,6 +354,10 @@ class IntervalsIntegration(SyncIntegration):
w.workouttype = mytypes.intervalsmappinginv[data['type']]
except KeyError:
pass
try:
w.sub_type = subtypemapping[data['sub_type']]
except KeyError:
pass
try:
w.rpe = data['icu_rpe']
if w.rpe is None:
@@ -873,7 +893,7 @@ class IntervalsIntegration(SyncIntegration):
try:
ps.comment = data['description']
except KeyError:
ps.comment = ''
ps.comment = ' '
ps.startdate = arrow.get(data['start_date_local']).datetime
ps.enddate = arrow.get(data['end_date_local']).datetime
ps.preferreddate = arrow.get(data['start_date_local']).datetime

View File

@@ -3585,6 +3585,45 @@ def handle_nk_async_workout(alldata, userid, nktoken, nkid, delaysec, defaulttim
return workoutid
@app.task
def handle_intervals_updateworkout(workout, debug=False, **kwargs):
rower = workout.user
intervalstoken = rower.intervals_token
authorizationstring = str('Bearer ' + intervalstoken)
headers = {
'authorization': authorizationstring
}
thetype = mytypes.intervalsmapping[workout.workouttype]
jsondict = {'type': thetype}
subtype = workout.sub_type
if subtype == "Warming Up":
jsondict['sub_type'] = "WARMUP"
elif subtype == "Cooling Down":
jsondict['sub_type'] = "COOLDOWN"
elif subtype == "Commute":
jsondict['commute'] = True
jsondict['sub_type'] = "COMMUTE"
else:
jsondict['sub_type'] = "NONE"
if workout.rpe is not None and workout.rpe > 0:
jsondict['icu_rpe'] = workout.rpe
jsondict['commute'] = workout.is_commute
if workout.plannedsession:
jsondict['paired_event_id'] = workout.plannedsession.intervals_icu_id
url = "https://intervals.icu/api/v1/activity/{activityid}".format(activityid=workout.uploadedtointervals)
response = requests.put(url, headers=headers, json=jsondict)
response = requests.put(url, headers=headers, json=jsondict)
if response.status_code not in [200, 201]:
dologging('intervals.icu.log', response.reason)
return 0
@app.task
def handle_intervals_getworkout(rower, intervalstoken, workoutid, debug=False, **kwargs):
authorizationstring = str('Bearer '+intervalstoken)

Binary file not shown.

View File

@@ -937,6 +937,7 @@ def intervals_webhook_view(request):
else:
dologging("intervals_webhooks.log",request.body)
data = json.loads(request.body)
print(data)
try:
verificationtoken = data['secret']
except KeyError:

View File

@@ -251,6 +251,7 @@ from rowers.rows import handle_uploaded_file, handle_uploaded_image
from rowers.plannedsessions import *
from rowers.tasks import handle_makeplot, handle_otwsetpower, handle_sendemailtcx, handle_sendemailcsv
from rowers.tasks import (
handle_intervals_updateworkout,
handle_post_workout_api,
handle_sendemail_newftp,
instroke_static,

View File

@@ -4611,6 +4611,12 @@ def workout_edit_view(request, id=0, message="", successmessage=""):
except IntegrityError: # pragma: no cover
pass
if row.uploadedtointervals is not None and row.user.intervals_auto_export:
_ = myqueue(queuehigh,
handle_intervals_updateworkout,
row
)
if ps: # pragma: no cover
add_workouts_plannedsession([row], ps, row.user)