mirror of
https://github.com/davegallant/rfd-notify.git
synced 2025-08-06 00:33:39 +00:00
Remove html formatting in notifications to support other notification systems
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
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:
|
||||
def send_notification(topic: Topic, expression: str, servers: str) -> None:
|
||||
if servers is None:
|
||||
logger.warning("APPRISE_URL is not set. Will not send notification")
|
||||
return
|
||||
@@ -18,30 +14,12 @@ def send_notification(
|
||||
apobj = apprise.Apprise()
|
||||
apobj.add(servers)
|
||||
|
||||
if topic.offer:
|
||||
dealer_name = topic.offer.dealer_name
|
||||
else:
|
||||
dealer_name = ""
|
||||
|
||||
subject = topic.title
|
||||
body = f"""\
|
||||
<b>Post age:</b> {datetime.now(timezone.utc) - datetime.fromisoformat(topic.post_time)}
|
||||
<br>
|
||||
<br>
|
||||
<b>Dealer:</b> {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}
|
||||
"""
|
||||
{API_BASE_URL}{topic.web_path}
|
||||
Age: {datetime.now(timezone.utc) - datetime.fromisoformat(topic.post_time)}
|
||||
Matched by expression: {expression}
|
||||
"""
|
||||
|
||||
logger.debug("Sending notification")
|
||||
|
||||
|
@@ -84,9 +84,8 @@ def look_for_matches(
|
||||
continue
|
||||
|
||||
if str(topic.topic_id) not in previous_matches:
|
||||
posts = get_topic(topic.topic_id)
|
||||
previous_matches[str(topic.topic_id)] = 1
|
||||
send_notification(topic, posts, expression, apprise_url)
|
||||
send_notification(topic, expression, apprise_url)
|
||||
else:
|
||||
logger.debug(f"Already matched topic '{topic.title}'")
|
||||
break
|
||||
|
Reference in New Issue
Block a user