async strava sync
This commit is contained in:
@@ -101,6 +101,7 @@ import rowers.utils as utils
|
||||
import requests
|
||||
import rowers.longtask as longtask
|
||||
import arrow
|
||||
import stravalib
|
||||
|
||||
from rowers.utils import get_strava_stream
|
||||
|
||||
@@ -135,6 +136,27 @@ def handle_c2_sync(workoutid,url,headers,data,debug=False,**kwargs):
|
||||
|
||||
return res
|
||||
|
||||
@app.task
|
||||
def handle_strava_sync(stravatoken,workoutid,filename,name,activity_type,description,debug=False,**kwargs):
|
||||
client = stravalib.Client(access_token=stravatoken)
|
||||
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)
|
||||
|
||||
result = update_workout_field_sql(workoutid,'uploadedtostrava',res.id,debug=debug)
|
||||
try:
|
||||
os.remove(filename)
|
||||
except WindowsError:
|
||||
pass
|
||||
|
||||
return 1
|
||||
|
||||
@app.task
|
||||
def handle_c2_import_stroke_data(c2token,
|
||||
c2id,workoutid,
|
||||
|
||||
Reference in New Issue
Block a user