fixed strava error
This commit is contained in:
@@ -102,6 +102,7 @@ import requests
|
||||
import rowers.longtask as longtask
|
||||
import arrow
|
||||
import stravalib
|
||||
from stravalib.exc import ActivityUploadFailed
|
||||
|
||||
from rowers.utils import get_strava_stream
|
||||
|
||||
@@ -171,17 +172,22 @@ def handle_runkeeper_sync(workoutid,url,headers,data,debug=False,**kwargs):
|
||||
@app.task
|
||||
def handle_strava_sync(stravatoken,workoutid,filename,name,activity_type,description,debug=False,**kwargs):
|
||||
client = stravalib.Client(access_token=stravatoken)
|
||||
failed = False
|
||||
with open(filename,'rb') as f:
|
||||
act = client.upload_activity(f,'tcx.gz',name=name)
|
||||
res = act.wait(poll_interval=5.0, timeout=60)
|
||||
try:
|
||||
act = client.update_activity(res.id,activity_type=activity_type,
|
||||
description=description,device_name='Rowsandall.com')
|
||||
except TypeError:
|
||||
act = client.update_activity(res.id,activity_type=activity_type,
|
||||
description=description)
|
||||
try:
|
||||
res = act.wait(poll_interval=5.0, timeout=60)
|
||||
except ActivityUploadFailed:
|
||||
failed = True
|
||||
if not failed:
|
||||
try:
|
||||
act = client.update_activity(res.id,activity_type=activity_type,
|
||||
description=description,device_name='Rowsandall.com')
|
||||
except TypeError:
|
||||
act = client.update_activity(res.id,activity_type=activity_type,
|
||||
description=description)
|
||||
|
||||
result = update_workout_field_sql(workoutid,'uploadedtostrava',res.id,debug=debug)
|
||||
result = update_workout_field_sql(workoutid,'uploadedtostrava',res.id,debug=debug)
|
||||
try:
|
||||
os.remove(filename)
|
||||
except WindowsError:
|
||||
|
||||
Reference in New Issue
Block a user