Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Photo links #14

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions swarm_to_sqlite/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def cli(db_path, token, load, save, since, silent):
bar.update(1)
if save:
saved.append(checkin)
if not db["events"].exists():
db["events"].create({ "id": str, "name": str}, pk="id")
ensure_foreign_keys(db)
create_views(db)
if save:
Expand Down
11 changes: 7 additions & 4 deletions swarm_to_sqlite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def save_checkin(checkin, db):
user = photo.pop("user")
cleanup_user(user)
db["users"].insert(user, pk="id", replace=True, alter=True)
photo["checkin_id"] = checkin["id"]
photo["user"] = user["id"]
photos_table.insert(photo, replace=True, alter=True)
# Handle posts
Expand Down Expand Up @@ -170,22 +171,24 @@ def create_views(db):
"""
select
checkins.id,
created,
checkins.created,
venues.id as venue_id,
venues.name as venue_name,
venues.latitude,
venues.longitude,
group_concat(categories.name) as venue_categories,
group_concat(distinct categories.name) as venue_categories,
shout,
createdBy,
events.name as event_name
events.name as event_name,
group_concat((photos.prefix || 'original' || photos.suffix), CHAR(10)) as photo_links
from checkins
join venues on checkins.venue = venues.id
left join events on checkins.event = events.id
join categories_venues on venues.id = categories_venues.venues_id
join categories on categories.id = categories_venues.categories_id
left join photos on checkins.id = photos.checkin_id
group by checkins.id
order by createdAt desc
order by checkins.createdAt desc
""",
),
):
Expand Down