Add humanize for relative times

This commit is contained in:
2025-03-18 17:00:36 -04:00
parent 87a205ae74
commit 823511e714
5 changed files with 23 additions and 21 deletions

View File

@@ -15,22 +15,8 @@ jobs:
id: prep id: prep
run: | run: |
IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/rfd-notify IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/rfd-notify
VERSION=${GITHUB_REF##*/} VERSION=2
if [[ $GITHUB_REF == refs/heads/main ]]; then
VERSION=1
fi
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
TAGS="${IMAGE_NAME}:${VERSION}" TAGS="${IMAGE_NAME}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${IMAGE_NAME}:2"
fi
echo ::set-output name=tags::${TAGS} echo ::set-output name=tags::${TAGS}
- name: Set up Docker Buildx - name: Set up Docker Buildx

View File

@@ -13,7 +13,7 @@ This was originally written before [alerts](https://www.redflagdeals.com/alerts/
The simplest way to get started is to clone this repo, and run with docker: The simplest way to get started is to clone this repo, and run with docker:
```sh ```sh
docker run -it -v "$(pwd)/examples/config.yml:/app/config.yml" ghcr.io/davegallant/rfd-notify:1 docker run -it -v "$(pwd)/examples/config.yml:/app/config.yml" ghcr.io/davegallant/rfd-notify:2
``` ```
To run the code with [poetry](https://python-poetry.org/), clone this repo and run the following: To run the code with [poetry](https://python-poetry.org/), clone this repo and run the following:

18
poetry.lock generated
View File

@@ -1,4 +1,4 @@
# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. # This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand.
[[package]] [[package]]
name = "apprise" name = "apprise"
@@ -242,6 +242,20 @@ files = [
[package.extras] [package.extras]
test = ["pytest (>=6)"] test = ["pytest (>=6)"]
[[package]]
name = "humanize"
version = "4.12.1"
description = "Python humanize utilities"
optional = false
python-versions = ">=3.9"
files = [
{file = "humanize-4.12.1-py3-none-any.whl", hash = "sha256:86014ca5c52675dffa1d404491952f1f5bf03b07c175a51891a343daebf01fea"},
{file = "humanize-4.12.1.tar.gz", hash = "sha256:1338ba97415c96556758a6e2f65977ed406dddf4620d4c6db9bbdfd07f0f1232"},
]
[package.extras]
tests = ["freezegun", "pytest", "pytest-cov"]
[[package]] [[package]]
name = "idna" name = "idna"
version = "3.7" version = "3.7"
@@ -731,4 +745,4 @@ dev = ["black (>=19.3b0)", "pytest (>=4.6.2)"]
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.10" python-versions = "^3.10"
content-hash = "5aa566ddd905579ebaaa263114dbf1b5452b8d86c81e92ff58f8f54be1ce996f" content-hash = "54449b2b645fde726694dda72179361a63d12eeeccb7607e2fadfd63d02fcdce"

View File

@@ -1,8 +1,8 @@
[tool.poetry] [tool.poetry]
name = "rfd-notify" name = "rfd-notify"
version = "2.0.0" version = "2.1.0"
description = "get notified of deals based on regex" description = "get notified of deals based on regex"
authors = ["Dave Gallant <dave.gallant@gmail.com>"] authors = ["Dave Gallant <davegallant@gmail.com>"]
readme = "README.md" readme = "README.md"
packages = [{include = "rfd_notify"}] packages = [{include = "rfd_notify"}]
@@ -12,6 +12,7 @@ requests = "^2.31.0"
pyyaml = "^6.0" pyyaml = "^6.0"
loguru = "^0.7.2" loguru = "^0.7.2"
apprise = "^1.7.1" apprise = "^1.7.1"
humanize = "^4.12.1"
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]
pytest = "^8.0.0" pytest = "^8.0.0"

View File

@@ -1,6 +1,7 @@
from datetime import datetime, timezone from datetime import datetime, timezone
import apprise import apprise
import humanize
from models.topic import Topic from models.topic import Topic
from loguru import logger from loguru import logger
from constants import API_BASE_URL from constants import API_BASE_URL
@@ -17,7 +18,7 @@ def send_notification(topic: Topic, expression: str, servers: str) -> None:
subject = topic.title subject = topic.title
body = f"""\ body = f"""\
{API_BASE_URL}{topic.web_path} {API_BASE_URL}{topic.web_path}
Age: {datetime.now(timezone.utc) - datetime.fromisoformat(topic.post_time)} {humanize.naturaltime(datetime.now(timezone.utc) - datetime.fromisoformat(topic.post_time))}
Matched by expression: {expression} Matched by expression: {expression}
""" """