From a2c0048ba1dde0247a847a0f0d43df2d44c6ac66 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 25 Jun 2018 10:22:39 +0200 Subject: [PATCH] small bug fixes --- rowers/stravastuff.py | 7 ++++++- rowers/views.py | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/rowers/stravastuff.py b/rowers/stravastuff.py index c14e6817..c502b2f0 100644 --- a/rowers/stravastuff.py +++ b/rowers/stravastuff.py @@ -38,6 +38,11 @@ from stravalib.exc import ActivityUploadFailed,TimeoutExceeded from rowsandall_app.settings import C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET, STRAVA_CLIENT_ID, STRAVA_REDIRECT_URI, STRAVA_CLIENT_SECRET +try: + from json.decoder import JSONDecodeError +except ImportError: + JSONDecodeError = ValueError + # Exponentially weighted moving average # Used for data smoothing of the jagged data obtained by Strava # See bitbucket issue 72 @@ -106,7 +111,7 @@ def get_token(code): try: token_json = response.json() thetoken = token_json['access_token'] - except KeyError: + except (KeyError,JSONDecodeError): thetoken = 0 return [thetoken] diff --git a/rowers/views.py b/rowers/views.py index c6e5b1e9..ab887870 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -1409,8 +1409,11 @@ def add_workout_from_runkeeperdata(user,importid,data): unixtime = cum_time+starttimeunix - unixtime[0] = starttimeunix - + try: + unixtime[0] = starttimeunix + except IndexError: + return (0,'No data to import') + df['TimeStamp (sec)'] = unixtime