mirror of
https://github.com/davegallant/rfd-notify.git
synced 2025-08-06 00:33:39 +00:00
Migrate to python (#265)
* Add initial python migration * Add pylint * Add pre-commit * Add Dockerfile * Add expression matching * Use shelve to store previous matches * Add notifications * Calculate post age * Update README.md
This commit is contained in:
42
rfd_notify/notifications.py
Normal file
42
rfd_notify/notifications.py
Normal file
@@ -0,0 +1,42 @@
|
||||
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:
|
||||
apobj = apprise.Apprise()
|
||||
apobj.add(servers)
|
||||
|
||||
subject = topic.title
|
||||
body = f"""\
|
||||
<b>Post age:</b> {datetime.now(timezone.utc) - datetime.fromisoformat(topic.post_time)}
|
||||
<br>
|
||||
<br>
|
||||
<b>Dealer:</b> {topic.offer.dealer_name}
|
||||
<br>
|
||||
<br>
|
||||
<b>Deal:</b> {topic.title}
|
||||
<br>
|
||||
<br>
|
||||
<b>Post:</b> {API_BASE_URL}{topic.web_path}\
|
||||
<br>
|
||||
<br>
|
||||
<b>Body:</b> {posts[0].body}
|
||||
<br>
|
||||
<br>
|
||||
<b>Matched by expression:</b> {expression}
|
||||
"""
|
||||
|
||||
logger.debug("Sending notification")
|
||||
|
||||
apobj.notify(
|
||||
body=body,
|
||||
title=subject,
|
||||
)
|
Reference in New Issue
Block a user