from pathlib import Path import sqlite3 from typing import Callable, cast from database.connection import get_conn from util.util import LOGGER from cross.post import Post class Service: def __init__(self, url: str, db: Path) -> None: self.url: str = url self.conn: sqlite3.Connection = get_conn(db) def get_post(self, url: str, user: str, identifier: str) -> sqlite3.Row | None: cursor = self.conn.cursor() _ = cursor.execute( """ SELECT * FROM posts WHERE service = ? AND user_id = ? AND identifier = ? """, (url, user, identifier), ) return cast(sqlite3.Row, cursor.fetchone()) def get_post_by_id(self, id: int) -> sqlite3.Row | None: cursor = self.conn.cursor() _ = cursor.execute("SELECT * FROM posts WHERE id = ?", (id,)) return cast(sqlite3.Row, cursor.fetchone()) def close(self): self.conn.close() class OutputService(Service): def __init__(self, url: str, db: Path) -> None: super().__init__(url, db) def accept_post(self, post: Post): LOGGER.warning("NOT IMPLEMENTED, accept_post %s", post.id) def delete_post(self, post_id: str): LOGGER.warning("NOT IMPLEMENTED, delete_post %s", post_id) def accept_repost(self, repost_id: str, reposted_id: str): LOGGER.warning("NOT IMPLEMENTED, accept_repost %s", repost_id) def delete_repost(self, repost_id: str): LOGGER.warning("NOT IMPLEMENTED, delete_repost %s", repost_id) class InputService(Service): def __init__(self, url: str, db: Path) -> None: super().__init__(url, db) async def listen(self, outputs: list[OutputService], submitter: Callable[[Callable[[], None]], None]): pass