from typing import List from datetime import datetime, timezone import apprise from models.topic import Topic from models.post import Post from loguru import logger from constants import API_BASE_URL def send_notification( topic: Topic, posts: List[Post], expression: str, servers: str ) -> None: if servers is None: logger.warning("APPRISE_URL is not set. Will not send notifcation") return apobj = apprise.Apprise() apobj.add(servers) subject = topic.title body = f"""\ Post age: {datetime.now(timezone.utc) - datetime.fromisoformat(topic.post_time)}

Dealer: {topic.offer.dealer_name}

Deal: {topic.title}

Post: {API_BASE_URL}{topic.web_path}\

Body: {posts[0].body}

Matched by expression: {expression} """ logger.debug("Sending notification") apobj.notify( body=body, title=subject, )