diff --git a/tapiriik/services/Strava/strava.py b/tapiriik/services/Strava/strava.py index f466b3769..201c97b1b 100644 --- a/tapiriik/services/Strava/strava.py +++ b/tapiriik/services/Strava/strava.py @@ -174,8 +174,6 @@ def DownloadActivityList(self, svcRecord, exhaustive=False): activity.Stats.Cadence.update(ActivityStatistic(ActivityStatisticUnit.RevolutionsPerMinute, avg=ride["average_cadence"])) if "average_temp" in ride: activity.Stats.Temperature.update(ActivityStatistic(ActivityStatisticUnit.DegreesCelcius, avg=ride["average_temp"])) - if "calories" in ride: - activity.Stats.Energy = ActivityStatistic(ActivityStatisticUnit.Kilocalories, value=ride["calories"]) activity.Name = ride["name"] activity.Private = ride["private"] activity.Stationary = ride["manual"] @@ -216,6 +214,18 @@ def DownloadActivity(self, svcRecord, activity): return activity activityID = activity.ServiceData["ActivityID"] + #Note (smelikyan): request activity details in order to extract calories stat + details = requests.get("https://www.strava.com/api/v3/activities/" + str(activityID), headers=self._apiHeaders(svcRecord)) + if details.status_code == 401: + raise APIException("No authorization to download activity", block=True, user_exception=UserException(UserExceptionType.Authorization, intervention_required=True)) + try: + details = details.json() + except ValueError: + raise APIException("Activity details data returned is not JSON") + + if "calories" in details: + activity.Stats.Energy = ActivityStatistic(ActivityStatisticUnit.Kilocalories, value=details["calories"]) + streamdata = requests.get("https://www.strava.com/api/v3/activities/" + str(activityID) + "/streams/time,altitude,heartrate,cadence,watts,temp,moving,latlng,distance,velocity_smooth", headers=self._apiHeaders(svcRecord)) if streamdata.status_code == 401: raise APIException("No authorization to download activity", block=True, user_exception=UserException(UserExceptionType.Authorization, intervention_required=True))