faster strava sync
This commit is contained in:
@@ -439,15 +439,19 @@ def createstravaworkoutdata(w,dozip=True):
|
|||||||
# Upload the TCX file to Strava and set the workout activity type
|
# Upload the TCX file to Strava and set the workout activity type
|
||||||
# to rowing on Strava
|
# to rowing on Strava
|
||||||
def handle_stravaexport(f2,workoutname,stravatoken,description='',
|
def handle_stravaexport(f2,workoutname,stravatoken,description='',
|
||||||
activity_type='Rowing'):
|
activity_type='Rowing',async=False):
|
||||||
# w = Workout.objects.get(id=workoutid)
|
# w = Workout.objects.get(id=workoutid)
|
||||||
client = stravalib.Client(access_token=stravatoken)
|
client = stravalib.Client(access_token=stravatoken)
|
||||||
|
|
||||||
act = client.upload_activity(f2,'tcx.gz',name=workoutname)
|
act = client.upload_activity(f2,'tcx.gz',name=workoutname)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = act.wait(poll_interval=5.0,timeout=30)
|
if async:
|
||||||
message = 'Workout successfully synchronized to Strava'
|
res = act.wait(poll_interval=1.0, timeout=10)
|
||||||
|
message = 'Workout successfully synchronized to Strava'
|
||||||
|
else:
|
||||||
|
res = act.wait(poll_interval=5.0,timeout=30)
|
||||||
|
message = 'Workout successfully synchronized to Strava'
|
||||||
except:
|
except:
|
||||||
res = 0
|
res = 0
|
||||||
message = 'Strava upload timed out'
|
message = 'Strava upload timed out'
|
||||||
@@ -621,7 +625,7 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
|
|
||||||
return id,message
|
return id,message
|
||||||
|
|
||||||
def workout_strava_upload(user,w):
|
def workout_strava_upload(user,w, async=False):
|
||||||
try:
|
try:
|
||||||
thetoken = strava_open(user)
|
thetoken = strava_open(user)
|
||||||
except NoTokenError:
|
except NoTokenError:
|
||||||
@@ -644,7 +648,7 @@ def workout_strava_upload(user,w):
|
|||||||
f,w.name,
|
f,w.name,
|
||||||
r.stravatoken,
|
r.stravatoken,
|
||||||
description=w.notes+'\n from '+w.workoutsource+' via rowsandall.com',
|
description=w.notes+'\n from '+w.workoutsource+' via rowsandall.com',
|
||||||
activity_type=r.stravaexportas)
|
activity_type=r.stravaexportas,async=async)
|
||||||
if res==0:
|
if res==0:
|
||||||
message = mes
|
message = mes
|
||||||
w.uploadedtostrava = -1
|
w.uploadedtostrava = -1
|
||||||
|
|||||||
@@ -507,7 +507,7 @@ def make_private(w,options):
|
|||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def do_sync(w,options):
|
def do_sync(w,options, async=False):
|
||||||
try:
|
try:
|
||||||
upload_to_strava = options['upload_to_Strava']
|
upload_to_strava = options['upload_to_Strava']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -532,7 +532,7 @@ def do_sync(w,options):
|
|||||||
if ('upload_to_Strava' in options and upload_to_strava) or (w.user.strava_auto_export and ispromember(w.user.user)):
|
if ('upload_to_Strava' in options and upload_to_strava) or (w.user.strava_auto_export and ispromember(w.user.user)):
|
||||||
try:
|
try:
|
||||||
message,id = stravastuff.workout_strava_upload(
|
message,id = stravastuff.workout_strava_upload(
|
||||||
w.user.user,w
|
w.user.user,w,async=async
|
||||||
)
|
)
|
||||||
except NoTokenError:
|
except NoTokenError:
|
||||||
id = 0
|
id = 0
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
from rowers.views.statements import *
|
from rowers.views.statements import *
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Export workout to TCX and send to user's email address
|
# Export workout to TCX and send to user's email address
|
||||||
@permission_required('workout.change_workout',fn=get_workout_by_opaqueid,raise_exception=True)
|
@permission_required('workout.change_workout',fn=get_workout_by_opaqueid,raise_exception=True)
|
||||||
def workout_tcxemail_view(request,id=0):
|
def workout_tcxemail_view(request,id=0):
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ def workout_strava_upload_view(request,id=0):
|
|||||||
f,w.name,
|
f,w.name,
|
||||||
r.stravatoken,
|
r.stravatoken,
|
||||||
description=newnotes,
|
description=newnotes,
|
||||||
activity_type=activity_type)
|
activity_type=activity_type,async=True)
|
||||||
if res==0:
|
if res==0:
|
||||||
messages.error(request,mes)
|
messages.error(request,mes)
|
||||||
w.uploadedtostrava = -1
|
w.uploadedtostrava = -1
|
||||||
|
|||||||
@@ -4500,7 +4500,7 @@ def workout_upload_api(request):
|
|||||||
|
|
||||||
w = Workout.objects.get(id=id)
|
w = Workout.objects.get(id=id)
|
||||||
|
|
||||||
uploads.do_sync(w,post_data)
|
uploads.do_sync(w,post_data,async=True)
|
||||||
|
|
||||||
if make_plot:
|
if make_plot:
|
||||||
res, jobid = uploads.make_plot(r,w,f1,f2,plottype,t)
|
res, jobid = uploads.make_plot(r,w,f1,f2,plottype,t)
|
||||||
|
|||||||
Reference in New Issue
Block a user