def sync_strava_workouts(user_id, auth_token): user = User.by_id(user_id) if user.count() != 1: raise SyncWorkerException("strava") user = user.one() page = 0 items_per_page = 25 while True: response = fetch_strava_activities(auth_token, page, items_per_page) total_pages = math.ceil(len(response) / items_per_page) for activity in response: if not has_synced_workout(response["id"], "strava"): sync_strava_activity(user, auth_token, activity) page += 1 if page >= total_pages: break
def sync_runkeeper_workouts(user_id, auth_token): user = User.by_id(user_id) if user.count() != 1: raise SyncWorkerException('runkeeper') user = user.one() page = 0 items_per_page = 25 while True: response = fetch_runkeeper_activities(auth_token, page, items_per_page) total_pages = math.ceil(response['size' / items_per_page]) for activity in response['items']: identifier = parse_runkeeper_identifier(activity['uri']) if not has_synced_workout(identifier, 'runkeeper'): sync_runkeeper_activtiy(identifier, user, auth_token) page += 1 if page >= total_pages: break