-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
72 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,9 @@ | |
'start_date', | ||
'type', | ||
} | ||
optional_columns = { | ||
'start_latlng', | ||
} | ||
|
||
|
||
class Activity: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import csv | ||
import json | ||
from os import PathLike | ||
import sqlite3 | ||
from typing import Iterable | ||
from typing import TextIO | ||
from typing import Union | ||
|
||
from .data import Activity | ||
from .data import essential_columns | ||
|
||
|
||
def read_input_csv(inp: TextIO) -> Iterable[Activity]: | ||
""" | ||
Read activities from CSV generated from this command: | ||
sqlite3 ~/.local/share/strava_offline/strava.sqlite \ | ||
".mode csv" \ | ||
".headers on" \ | ||
"SELECT distance, elapsed_time, id, moving_time, name, start_date, \ | ||
json_extract(json, '$.start_latlng') AS 'start_latlng', total_elevation_gain, type FROM activity" \ | ||
>activities.csv | ||
""" | ||
for r in csv.DictReader(inp): | ||
assert essential_columns <= r.keys() | ||
r['id'] = int(r['id']) | ||
r['distance'] = float(r['distance']) | ||
r['total_elevation_gain'] = float(r['total_elevation_gain']) | ||
r['moving_time'] = int(r['moving_time']) | ||
r['elapsed_time'] = int(r['elapsed_time']) | ||
if 'start_latlng' in r: | ||
r['start_latlng'] = json.loads(r['start_latlng']) | ||
yield Activity(r) | ||
|
||
|
||
def read_strava_offline(db_filename: Union[str, PathLike]) -> Iterable[Activity]: | ||
""" | ||
Read activities from strava-offline database. | ||
""" | ||
with sqlite3.connect(db_filename) as db: | ||
db.row_factory = sqlite3.Row | ||
|
||
for r in db.execute('SELECT * FROM activity'): | ||
r_json = json.loads(r['json']) | ||
r = {**r_json, **r} | ||
assert essential_columns <= set(r.keys()) | ||
yield Activity(r) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters