diff --git a/rowers/c2stuff.py b/rowers/c2stuff.py index 503dd850..d7544dfc 100644 --- a/rowers/c2stuff.py +++ b/rowers/c2stuff.py @@ -238,7 +238,7 @@ def create_async_workout(alldata,user,c2id): duration = dataprep.totaltime_sec_to_string(totaltime) try: - timezone_str = tz(data['timezone']) + timezone_str = data['timezone'] except: timezone_str = 'UTC' diff --git a/rowers/tasks.py b/rowers/tasks.py index fdaf22fe..9bfb8d28 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -419,7 +419,7 @@ def handle_c2_import_stroke_data(c2token, duration = datetime.datetime.strptime(duration,'%H:%M:%S.%f').time() try: - timezone_str = tz(workoutdata['timezone']) + timezone_str = workoutdata['timezone'] except: timezone_str = 'UTC' @@ -2991,7 +2991,7 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone c2id = data['id'] workouttype = data['type'] verified = data['verified'] - startdatetime = iso8601.parse_date(data['date']) + startdatetime = iso8601.parse_date(data['date_utc']) weightclass = data['weight_class'] try: @@ -3013,21 +3013,18 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone totaltime = data['time']/10. duration = totaltime_sec_to_string(totaltime) + starttimeunix = arrow.get(startdatetime).timestamp()-totaltime + startdatetime = arrow.get(starttimeunix) - try: - timezone_str = tz(data['timezone']) - except: - timezone_str = defaulttimezone + timezone = pytz.timezone(data['timezone']) + startdatetime = startdatetime.astimezone(timezone) - startdatetime = startdatetime.replace(tzinfo=None) - tz = pytz.timezone(timezone_str) - startdatetime = tz.localize(startdatetime) workoutdate = startdatetime.astimezone( - pytz.timezone(timezone_str) + timezone ).strftime('%Y-%m-%d') starttime = startdatetime.astimezone( - pytz.timezone(timezone_str) + timezone ).strftime('%H:%M:%S') try: @@ -3056,8 +3053,6 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone cum_time = res[0] lapidx = res[1] - starttimeunix = arrow.get(startdatetime).timestamp() - starttimeunix = starttimeunix-cum_time.max() unixtime = cum_time+starttimeunix # unixtime[0] = starttimeunix @@ -3134,6 +3129,7 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone 'workouttype':workouttype, 'boattype':'1x', 'c2id':c2id, + 'timezone':str(timezone) } session = requests.session() @@ -3165,8 +3161,11 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone parkedids = [] with open('c2blocked.json','r') as c2blocked: - jsondata = json.load(c2blocked) - parkedids = jsondata['ids'] + try: + jsondata = json.load(c2blocked) + parkedids = jsondata['ids'] + except JSONDecodeError: + parkedids = [] newparkedids = [id for id in parkedids if id != newc2id] with open('c2blocked.json','wt') as c2blocked: @@ -3364,7 +3363,7 @@ def fetch_strava_workout(stravatoken,oauth_data,stravaid,csvfilename,userid,debu comments = ' ' try: - thetimezone = tz(workoutsummary['timezone']) + thetimezone = workoutsummary['timezone'] except: thetimezone = 'UTC' diff --git a/rowers/tests/test_imports.py b/rowers/tests/test_imports.py index cd4640a3..bfef0eee 100644 --- a/rowers/tests/test_imports.py +++ b/rowers/tests/test_imports.py @@ -158,6 +158,7 @@ class C2Objects(DjangoTestCase): self.r.c2token = '12' self.r.c2refreshtoken = 'ab' self.r.tokenexpirydate = arrow.get(datetime.datetime.now()+datetime.timedelta(days=1)).datetime + self.r.defaulttimezone = 'Europe/Prague' self.r.save() self.c.login(username='john',password='koeinsloot') @@ -342,6 +343,7 @@ class C2Objects(DjangoTestCase): res = tasks.handle_c2_async_workout(alldata,self.u.id,self.r.c2token,33991243,0,self.r.defaulttimezone) self.assertEqual(res,1) + @override_settings(TESTING=True) class C2ObjectsTokenExpired(DjangoTestCase): def setUp(self): diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 1f46d518..0767310c 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -4813,8 +4813,8 @@ def workout_upload_api(request): totalDistance = post_data.get('totalDistance',None) elapsedTime = post_data.get('elapsedTime',None) summary = post_data.get('summary',None) - - + timezone = post_data.get('timezone',None) + r = None if form.is_valid(): t = form.cleaned_data['title'] @@ -4905,6 +4905,13 @@ def workout_upload_api(request): return JSONResponse(status=200,data=message) w = Workout.objects.get(id=id) + if timezone is not None: + w.startdatetime = w.startdatetime.astimezone(pytz.timezone(timezone)) + w.workoutdate = w.startdatetime.strftime('%Y-%m-%d') + w.starttime = w.starttime.strftime('%H:%M:%S') + w.timezone = timezone + w.save() + if make_plot: # pragma: no cover