diyalgo/diyalgo/workers/timeline.py

28 lines
893 B
Python

import pdb
from mastodon import Mastodon
from sqlmodel import Session, select
from tqdm.asyncio import tqdm
from diyalgo.expansions.timeline import fetch_timeline
from diyalgo.models.status import Status
def populate_timeline(
client: Mastodon,
session: Session,
**kwargs
):
# try:
for posts in fetch_timeline(client, 'public', **kwargs):
for post in posts:
if post.reblog is not None:
statement = select(Status).where(Status.id == post.reblog.id)
existing_reblog = session.exec(statement).first()
if existing_reblog is not None:
post.reblog = existing_reblog
statement = select(Status).where(Status.id == post.id)
existing = session.exec(statement).first()
if existing is None:
session.add(post)
session.commit()