hoping strava webhooks will work
This commit is contained in:
@@ -325,14 +325,15 @@ def create_async_workout(alldata,user,stravaid,debug=False):
|
||||
|
||||
from rowers.utils import get_strava_stream
|
||||
|
||||
def async_get_workout(user,stravaid,workout):
|
||||
def async_get_workout(user,stravaid):
|
||||
csvfilename = 'media/{code}_{stravaid}.csv'.format(code=uuid4().hex[:16],stravaid=stravaid)
|
||||
job = myqueue(queue,
|
||||
fetch_strava_workout,
|
||||
user.rower.stravatoken,
|
||||
oauth_data,
|
||||
workout.id,
|
||||
stravaid,
|
||||
workout.csvfilename,
|
||||
csvfilename,
|
||||
user.id,
|
||||
)
|
||||
return job
|
||||
|
||||
|
||||
@@ -2713,7 +2713,7 @@ def add2(x, y,debug=False,**kwargs):
|
||||
return x + y
|
||||
|
||||
@app.task
|
||||
def fetch_strava_workout(stravatoken,oauth_data,workoutid,stravaid,csvfilename,debug=False,**kwargs):
|
||||
def fetch_strava_workout(stravatoken,oauth_data,stravaid,csvfilename,userid,debug=False,**kwargs):
|
||||
fetchresolution = 'high'
|
||||
authorizationstring = str('Bearer '+stravatoken)
|
||||
headers = {'Authorization': authorizationstring,
|
||||
@@ -2925,19 +2925,30 @@ def fetch_strava_workout(stravatoken,oauth_data,workoutid,stravaid,csvfilename,d
|
||||
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
||||
|
||||
row = rowingdata.rowingdata(df=df)
|
||||
row.write_csv(csvfilename,gzip=True)
|
||||
row.write_csv(csvfilename,gzip=False)
|
||||
|
||||
summary = row.allstats()
|
||||
maxdist = df['cum_dist'].max()
|
||||
duration = row.duration
|
||||
|
||||
uploadoptions = {
|
||||
'secret':UPLOAD_SERVICE_SECRET,
|
||||
'user':userid,
|
||||
'file': csvfilename,
|
||||
'title': title,
|
||||
'workouttype':workouttype,
|
||||
'boattype':'1x',
|
||||
'stravaid':stravaid,
|
||||
}
|
||||
|
||||
print(uploadoptions)
|
||||
|
||||
session = requests.session()
|
||||
newHeaders = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
||||
session.headers.update(newHeaders)
|
||||
response = session.post(UPLOAD_SERVICE_URL,json=uploadoptions)
|
||||
|
||||
|
||||
update_strokedata(workoutid,row.df,debug=debug)
|
||||
res = update_workout_field_sql(workoutid,'workouttype',workouttype,debug=debug)
|
||||
res = update_workout_field_sql(workoutid,'name',title,debug=debug)
|
||||
res = update_workout_field_sql(workoutid,'notes',comments,debug=debug)
|
||||
res = update_workout_field_sql(workoutid,'summary',summary,debug=debug)
|
||||
res = update_workout_field_sql(workoutid,'distance',maxdist,debug=debug)
|
||||
res = update_workout_field_sql(workoutid,'duration',duration,debug=debug)
|
||||
|
||||
|
||||
return 1
|
||||
|
||||
@@ -1041,17 +1041,9 @@ def strava_webhook_view(request):
|
||||
except Rower.DoesNotExist:
|
||||
return HttpResponse(status=200)
|
||||
|
||||
w = Workout(
|
||||
user = r,
|
||||
csvfilename = 'media/{code}_{stravaid}'.format(code=uuid4().hex[:16],stravaid=stravaid),
|
||||
startdatetime = timezone.now(),
|
||||
uploadedtostrava=stravaid,
|
||||
)
|
||||
w.save()
|
||||
# too slow ...
|
||||
job = stravastuff.async_get_workout(r.user,stravaid,w)
|
||||
job = stravastuff.async_get_workout(r.user,stravaid)
|
||||
|
||||
print(w.id)
|
||||
|
||||
return HttpResponse(status=200)
|
||||
|
||||
|
||||
@@ -4717,7 +4717,7 @@ def workout_upload_api(request):
|
||||
message = {'status':'false','message':'unable to process file: '+message}
|
||||
else:
|
||||
message = {'status': 'false', 'message': 'unable to process file'}
|
||||
print(message)
|
||||
|
||||
return JSONResponse(status=400,data=message)
|
||||
if id == -1:
|
||||
message = {'status': 'true', 'message':message}
|
||||
|
||||
Reference in New Issue
Block a user