From 6e61b3fa72191d8de32e279aa2adcf88ba041bb7 Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Tue, 9 Feb 2021 23:02:54 +0000 Subject: [PATCH] Skip downloading GPX for activities without any location data This should fix the gpx download crashing when trying to download activities that only have heart rate data, like swims recorded using smartwatches. --- src/strava_offline/gpx.py | 2 +- src/strava_offline/sqlite.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/strava_offline/gpx.py b/src/strava_offline/gpx.py index b7dfe28..5f0b9b1 100644 --- a/src/strava_offline/gpx.py +++ b/src/strava_offline/gpx.py @@ -47,7 +47,7 @@ def download_gpx(strava: StravaWeb, activity_id: int, path: Path) -> None: def download_activities(db: sqlite3.Connection, strava: StravaWeb, dir_activities: Path) -> None: - for activity in db.execute("SELECT id FROM activity WHERE upload_id IS NOT NULL"): + for activity in db.execute("SELECT id FROM activity WHERE upload_id IS NOT NULL AND has_location_data"): activity_id = int(activity['id']) if find_gpx(dir_activities, activity_id): continue diff --git a/src/strava_offline/sqlite.py b/src/strava_offline/sqlite.py index c873a89..f94d1a1 100644 --- a/src/strava_offline/sqlite.py +++ b/src/strava_offline/sqlite.py @@ -35,7 +35,7 @@ def database(config: config.DatabaseConfig) -> Iterator[sqlite3.Connection]: # * sync_activity # # The tables will be recreated using the stored json data and the new schema. -SCHEMA_VERSION = 1 +SCHEMA_VERSION = 2 def schema_init(db: sqlite3.Connection) -> None: @@ -60,6 +60,7 @@ def schema_init(db: sqlite3.Connection) -> None: ", gear_id TEXT" ", type TEXT" ", commute BOOLEAN" + ", has_location_data BOOLEAN" ")" )) @@ -150,8 +151,9 @@ def sync_activity(activity, db: sqlite3.Connection): ", gear_id" ", type" ", commute" + ", has_location_data" ")" - "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ), ( activity['id'], @@ -166,6 +168,7 @@ def sync_activity(activity, db: sqlite3.Connection): activity['gear_id'], activity['type'], activity['commute'], + activity['start_latlng'] is not None, ) )