diff --git a/rowers/stravastuff.py b/rowers/stravastuff.py index 2a2c1c9c..7c38e7f2 100644 --- a/rowers/stravastuff.py +++ b/rowers/stravastuff.py @@ -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 diff --git a/rowers/tasks.py b/rowers/tasks.py index ff3ec212..72a2bd32 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -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 diff --git a/rowers/views/importviews.py b/rowers/views/importviews.py index f0ecc68d..115fcfec 100644 --- a/rowers/views/importviews.py +++ b/rowers/views/importviews.py @@ -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) diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 83dffac6..44ed35f7 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -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}