From d04200d1ec38ba7b21692146d53d8a5cabd61378 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Sun, 22 Jan 2017 20:35:51 +0100 Subject: [PATCH] some more error detection code --- rowers/stravastuff.py | 11 ++++++++++- rowers/views.py | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/rowers/stravastuff.py b/rowers/stravastuff.py index 5a3d59a1..113d088f 100644 --- a/rowers/stravastuff.py +++ b/rowers/stravastuff.py @@ -226,7 +226,16 @@ def createstravaworkoutdata(w): # to rowing on Strava def handle_stravaexport(file,workoutname,stravatoken,description=''): # w = Workout.objects.get(id=workoutid) - client = stravalib.Client(access_token=stravatoken) + try: + client = stravalib.Client(access_token=stravatoken) + except: + with open("media/stravaerrors.log","a") as errorlog: + errorstring = str(sys.exc_info()[0]) + timestr = time.strftime("%Y%m%d-%H%M%S") + errorlog.write(timestr+errorstring+"\r\n") + errorlog.write("stravastuff.py line 236\r\n") + return 0 + try: act = client.upload_activity(file,'tcx',name=workoutname) res = act.wait(poll_interval=5.0) diff --git a/rowers/views.py b/rowers/views.py index 1b2e35f3..ff85a1d7 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -868,6 +868,18 @@ def workout_strava_upload_view(request,id=0): res = stravastuff.handle_stravaexport(f,w.name, r.stravatoken, description=w.notes) + if res==0: + message = "Strava Upload error: %s" % e + w.uploadedtostrava = -1 + w.save() + os.remove(tcxfile) + url = reverse(workout_export_view, + kwargs = { + 'id':str(w.id), + }) + response = HttpResponseRedirect(url) + return response + except: with open("media/stravaerrors.log","a") as errorlog: errorstring = str(sys.exc_info()[0])