Skip to content

Commit

Permalink
Skip downloading GPX for activities without any location data
Browse files Browse the repository at this point in the history
This should fix the gpx download crashing when trying to download
activities that only have heart rate data, like swims recorded using
smartwatches.
  • Loading branch information
liskin committed Feb 9, 2021
1 parent 69cfa37 commit 6e61b3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/strava_offline/gpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/strava_offline/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -60,6 +60,7 @@ def schema_init(db: sqlite3.Connection) -> None:
", gear_id TEXT"
", type TEXT"
", commute BOOLEAN"
", has_location_data BOOLEAN"
")"
))

Expand Down Expand Up @@ -150,8 +151,9 @@ def sync_activity(activity, db: sqlite3.Connection):
", gear_id"
", type"
", commute"
", has_location_data"
")"
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
),
(
activity['id'],
Expand All @@ -166,6 +168,7 @@ def sync_activity(activity, db: sqlite3.Connection):
activity['gear_id'],
activity['type'],
activity['commute'],
activity['start_latlng'] is not None,
)
)

Expand Down

0 comments on commit 6e61b3f

Please sign in to comment.