From 9a4a12bf549ce599f96ea01a79a28433108a42d9 Mon Sep 17 00:00:00 2001 From: Dave Gallant Date: Thu, 13 Feb 2025 20:00:09 -0500 Subject: [PATCH] Remove html formatting in notifications to support other notification systems --- .github/workflows/push-container.yml | 2 +- README.md | 5 ++--- github-action/Dockerfile | 2 +- pyproject.toml | 2 +- rfd_notify/notifications.py | 32 +++++----------------------- rfd_notify/rfd.py | 3 +-- 6 files changed, 11 insertions(+), 35 deletions(-) diff --git a/.github/workflows/push-container.yml b/.github/workflows/push-container.yml index 4463976..8487216 100644 --- a/.github/workflows/push-container.yml +++ b/.github/workflows/push-container.yml @@ -28,7 +28,7 @@ jobs: TAGS="${IMAGE_NAME}:${VERSION}" if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then - TAGS="$TAGS,${IMAGE_NAME}:1" + TAGS="$TAGS,${IMAGE_NAME}:2" fi echo ::set-output name=tags::${TAGS} diff --git a/README.md b/README.md index 8b18903..aeb554f 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ This was originally written before [alerts](https://www.redflagdeals.com/alerts/ ## Prerequisites - either [poetry](https://github.com/python-poetry/poetry), docker, or github actions -- for email notifications [see supported providers](https://github.com/caronc/apprise/wiki/Notify_email#using-built-in-email-services) ## Usage @@ -30,7 +29,7 @@ The following environment variables are required: | VARIABLE | DESCRIPTION | | ----------- | ---------------------------------------------------------------------------------------- | -| APPRISE_URL | See [notifications](https://github.com/caronc/apprise#productivity-based-notifications). | +| APPRISE_URL | See [supported notifications](https://github.com/caronc/apprise#productivity-based-notifications). | ## Example Configuration @@ -93,7 +92,7 @@ With Gitlab Pipelines, the following configuration works: #.gitlab-ci.yml default: image: - name: ghcr.io/davegallant/rfd-notify:1 + name: ghcr.io/davegallant/rfd-notify:2 entrypoint: [""] run: diff --git a/github-action/Dockerfile b/github-action/Dockerfile index 254b929..f850589 100644 --- a/github-action/Dockerfile +++ b/github-action/Dockerfile @@ -1,3 +1,3 @@ -FROM ghcr.io/davegallant/rfd-notify:1 +FROM ghcr.io/davegallant/rfd-notify:2 ENTRYPOINT ["python", "/app/rfd_notify/cli.py", "-c", "config.yml"] diff --git a/pyproject.toml b/pyproject.toml index 0a2e49b..95728c4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "rfd-notify" -version = "1.0.0" +version = "2.0.0" description = "get notified of deals based on regex" authors = ["Dave Gallant "] readme = "README.md" diff --git a/rfd_notify/notifications.py b/rfd_notify/notifications.py index 45fc692..573260f 100644 --- a/rfd_notify/notifications.py +++ b/rfd_notify/notifications.py @@ -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"""\ - Post age: {datetime.now(timezone.utc) - datetime.fromisoformat(topic.post_time)} -
-
- Dealer: {dealer_name} -
-
- Deal: {topic.title} -
-
- Post: {API_BASE_URL}{topic.web_path}\ -
-
- Body: {posts[0].body} -
-
- Matched by expression: {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") diff --git a/rfd_notify/rfd.py b/rfd_notify/rfd.py index 309bd1d..2216445 100644 --- a/rfd_notify/rfd.py +++ b/rfd_notify/rfd.py @@ -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