From fb4dab66420c03604385ba6671dc16f9849d06af Mon Sep 17 00:00:00 2001 From: Lars Munch Date: Fri, 16 Mar 2018 00:34:09 +0100 Subject: [PATCH 1/3] Fix setting activity type --- garmin_uploader/api.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/garmin_uploader/api.py b/garmin_uploader/api.py index f80959d..494e490 100644 --- a/garmin_uploader/api.py +++ b/garmin_uploader/api.py @@ -11,8 +11,7 @@ URL_HOST_CONNECT = 'connect.garmin.com' URL_UPLOAD = 'https://connect.garmin.com/modern/proxy/upload-service/upload' URL_ACTIVITY_BASE = 'https://connect.garmin.com/modern/proxy/activity-service/activity' # noqa -URL_ACTIVITY_TYPE = 'https://connect.garmin.com/proxy/activity-service-1.2/json/type' # noqa -URL_ACTIVITY_TYPES = 'https://connect.garmin.com/proxy/activity-service-1.2/json/activity_types' # noqa +URL_ACTIVITY_TYPES = 'https://connect.garmin.com/modern/proxy/activity-service/activity/activityTypes' # noqa class GarminAPIException(Exception): @@ -199,17 +198,14 @@ def load_activity_types(self): if self.activity_types: return self.activity_types - logger.debug('Fecthing activity types') + logger.debug('Fetching activity types') resp = requests.get(URL_ACTIVITY_TYPES) if not resp.ok: raise GarminAPIException('Failed to retrieve activity types') # Store as a clean dict, mapping keys and lower case common name - types = resp.json()["dictionary"] - out = [(t['key'], t['key']) for t in types] - out += [(t['display'].lower(), t['key']) for t in types] - out = dict(out) - self.activity_types = out + types = resp.json() + self.activity_types = {t['typeKey']: t for t in types} logger.debug('Fetched {} activity types'.format(len(self.activity_types))) # noqa return self.activity_types @@ -228,14 +224,13 @@ def set_activity_type(self, session, activity): logger.error("Activity type '{}' not valid".format(activity.type)) return False - url = '{}/{}'.format(URL_ACTIVITY_TYPE, activity.id) + url = '{}/{}'.format(URL_ACTIVITY_BASE, activity.id) data = { - 'value': type_key, + 'activityId': activity.id, + 'activityTypeDTO': type_key } - res = session.post(url, data) + headers = dict(self.common_headers) # clone + headers['X-HTTP-Method-Override'] = 'PUT' # weird. again. + res = session.post(url, json=data, headers=headers) if not res.ok: raise GarminAPIException('Activity type not set: {}'.format(res.content)) # noqa - - res = res.json() - if "activityType" not in res or res["activityType"]["key"] != type_key: - raise GarminAPIException('Activity type not set: {}'.format(res.content)) # noqa From c9866bfdfeae8d112405cc7dcdf11f1b6be4e362 Mon Sep 17 00:00:00 2001 From: Lars Munch Date: Fri, 16 Mar 2018 00:34:09 +0100 Subject: [PATCH 2/3] Update help test for activity type --- garmin_uploader/help.txt | 42 ++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/garmin_uploader/help.txt b/garmin_uploader/help.txt index 535f716..f1adbdb 100644 --- a/garmin_uploader/help.txt +++ b/garmin_uploader/help.txt @@ -57,19 +57,37 @@ The following list of activity types should be valid for setting your activity type on Garmin Connect... - running, street_running, track_running, trail_running, - treadmill_running, cycling, cyclocross, downhill_biking, indoor_cycling, - mountain_biking, recumbent_cycling, road_biking, track_cycling, - fitness_equipment, elliptical, , indoor_cardio, indoor_rowing, - stair_climbing, strength_training, hiking, swimming, lap_swimming, - open_water_swimming, walking, casual_walking, speed_walking, transition, - swimToBikeTransition, bikeToRunTransition, runToBikeTransition, - motorcycling, other, backcountry_skiing_snowboarding, boating, - cross_country_skiing, driving_general, flying, golf, horseback_riding, - inline_skating, mountaineering, paddling, resort_skiing_snowboarding, - rowing, sailing, skate_skiing, skating, snowmobiling, snow_shoe, - stand_up_paddleboarding, whitewater_rafting_kayaking, wind_kite_surfing. + uncategorized + cycling, bmx, cyclocross, downhill_biking, gravel_cycling, + indoor_cycling, mountain_biking, recumbent_cycling, road_biking, + track_cycling, virtual_ride + + running, indoor_running, obstacle_run, street_running, track_running, + trail_running, treadmill_running, virtual_run + + fitness_equipment, elliptical, indoor_cardio, indoor_rowing, + stair_climbing, strength_training + + hiking, walking, casual_walking, speed_walking + + swimming, lap_swimming, open_water_swimming + + other, backcountry_skiing_snowboarding, boating, cross_country_skiing, + driving_general, floor_climbing, flying, golf, hang_gliding, + horseback_riding, hunting_fishing, inline_skating, mountaineering, + paddling, rc_drone, resort_skiing_snowboarding, rock_climbing, rowing, + sailing, skate_skiing, skating, sky_diving, snow_shoe, snowmobiling, + stand_up_paddleboarding, stop_watch, surfing, tennis, wakeboarding, + whitewater_rafting_kayaking, wind_kite_surfing, wingsuit_flying, yoga + + transition, bikeToRunTransition, runToBikeTransition, + swimToBikeTransition + + motorcycling, atv, motocross + + diving, apnea_diving, apnea_hunting, gauge_diving, multi_gas_diving, + single_gas_diving Examples: Upload file and set activty name: From b08832ea82f0b3bc1697c39e9bc9611e4a07b27b Mon Sep 17 00:00:00 2001 From: Lars Munch Date: Fri, 16 Mar 2018 09:03:33 +0100 Subject: [PATCH 3/3] Fix test for new activity types list --- tests/test_api.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index dab864b..ddb3955 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -12,8 +12,6 @@ def test_types(api): assert 'all' in types assert 'running' in types assert 'track_cycling' in types - assert 'track cycling' in types - assert types['track_cycling'] == types['track cycling'] def test_rename(api, user, sample_activity):