Skip to content

Commit

Permalink
rewritten
Browse files Browse the repository at this point in the history
  • Loading branch information
Kariton committed Jul 31, 2023
1 parent c97e1a8 commit 2bc430f
Show file tree
Hide file tree
Showing 15 changed files with 1,049 additions and 236 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# .dockerignore
__pycache__
*.pyc
*.pyo
*.pyd
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
FROM python:3.10.6
FROM python:3.11-alpine

ADD rss-ntfy.py .
RUN mkdir -p /rss-ntfy /etc/rss-ntfy
WORKDIR /rss-ntfy

COPY requirements.txt ./
ADD ./rss-ntfy/* /rss-ntfy/
COPY requirements.txt /rss-ntfy/

RUN pip install --no-cache-dir --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt

COPY . .
ENV PYTHONUNBUFFERED=1

CMD [ "python", "./rss-ntfy.py" ]
CMD ["python", "-u", "/rss-ntfy/rss-ntfy.py"]
108 changes: 77 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
# RSS ntfy

Very small RSS notifier using [ntfy](https://ntfy.sh/). I would *highly* recommend using a self hosted ntfy instance, so that you can use whatever ntfy names you want.
Very small RSS notifier using [ntfy](https://ntfy.sh/).
Forked from [julianorchard/rss-ntfy](https://github.com/julianorchard/rss-ntfy) and mostly rewritten to add furhter functionality.

It's designed for use alongside certain 'alternative frontend services'. I use it for:
I would *highly* recommend using a self hosted ntfy instance, so that you can use whatever ntfy names you want.

- [Nitter](https://github.com/zedeus/nitter), Twitter alternative
- [Proxitok](https://github.com/pablouser1/ProxiTok), a TikTok frontend

Both of these provide RSS feeds, which are on basically every page plus `/rss`: very handy.
Each post from a feed gets send as Markdown text.
In order to avoid duplicate posts, the "link" extracted from the RSS items is stored in a `_hist` file and
subsequently deleted once they are no longer present in the feed.
Some feeds might cause reposts because they re-include "old" listings.

## Usage

### Dependencies

- Python 3
- [BeautifulSoup4](https://www.crummy.com/software/BeautifulSoup/bs4/doc/), `pip install beautifulsoup4`
- [requests](https://requests.readthedocs.io/en/latest/) `python -m pip install requests`
- lxml-xml parser for BeautifulSoup
### Installation

```sh
pip install -i requirements.txt
pip install -r requirements.txt
mkdir /etc/rss-ntfy/
cp ./config/config.yml /etc/rss-ntfy/config.yml
```

Alternatively, use Docker compose:
Expand All @@ -28,36 +26,84 @@ Alternatively, use Docker compose:
docker compose up
```

This will create a persistent volume for the storage of the _hist files, too (if
run without Docker, these are put in `$XDG_CACHE_HOME`).
This will create a persistent volume for the storage of the `_hist` files, too (at least per default).

### Configuration

Edit the `config.yaml` file:
The script includes a set of default service definition and configuration which you might want to change.

[default.yml](rss-ntfy/default.yml) defines a set of `feeds`, `services`, `global` settings and `config`. **[DONT EDIT]**
Snippet:
```yaml
---

global: # settings to use as defaults
ntfy_server: https://ntfy.sh # server to use if no other is defined on service level
[...]

services: # service definition
github_release: # service name - referenced within the 'feeds' definition
service_feed: https://github.com/{{ name }}/releases.atom # where the rss feed is located
service_url: https://github.com/{{ name }} # used in the sub-title to link to the feed
ntfy_icon: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png
ntfy_subtitle_prefix: 🤖 GitHub Release
ntfy_subtitle_seperator: by
ntfy_tags: ['robot']

github_commit:
service_feed: https://github.com/{{ name }}/commits.atom
service_url: https://github.com/{{ name }}
ntfy_icon: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png
ntfy_subtitle_prefix: GitHub Commit on
ntfy_subtitle_seperator: by
ntfy_tags: ['robot']
[...]

feeds: # feeds to monitor from those services
github_release: []
github_commit: []
[...]

config:
cache_location: ~/.cache
run_on_startup: false
log_level: info
schedule: '*/30 * * * *' # crontab style expression - concurrent jobs are not possible
service_wait: 60 # time to wait between services
feed_wait: 5 # time to wait between posts of one feed
max_attempts: 3 # retry to send message; consider failed after
retry_wait: 30 # time to wait between retrys
```
To personalize your rss ntfycations you can override / extend those defaults with a [config.yml](config/config.yml):
With Docker: Don't mount the file directly and instead mount the whole config directory, otherwise automatic reload does not work.
Without Docker: The script expects the config to be available at `/etc/rss-ntfy/config.yml`

```yaml
# Example configuration
---
proxitok:
service: proxitok
rss-url: https://proxitok.pabloferreiro.es/@{{ user }}/rss
descriptor: 🎶 TikTok
global:
ntfy_topic: some_topic # topic to use if no other is defined on service level
teddit:
service: teddit
rss-url: https://teddit.net/r/{{ sub }}?api&type=rss
descriptor: 🎩 Reddit post
feeds:
reddit_subreddit:
- SysadminHumor+Programmerhumor
youtube:
- name: UCXuqSBlHAE6Xw-yeJA0Tunw
feed_display_name: LTT # the subtitle takes the feed name - which in some cases, like YouTube, is an ID
```
services:
reddit_subreddit:
ntfy_topic: one_topic
At this point the contents of the handlebar type substitutions (`{{ }}`) don't
matter; this will be replaced with the users/subreddits/thing-you-want-to-follow
in the files in the `rss-ntfy/` folder.
reddit_subreddit:
ntfy_topic: another_topic
```

*TODO: this is a not-nice way of doing this, possibly use more yaml*
At this point the contents of the handlebar type substitutions (`{{ }}` in `services`) don't matter;
this will be replaced with the users/thing-you-want-to-follow.

You can then use a [crontab](https://man7.org/linux/man-pages/man5/crontab.5.html) or a [systemd service](https://www.freedesktop.org/software/systemd/man/systemd.service.html) (or, on Windows, a [Task Scheduler](https://learn.microsoft.com/en-us/windows/win32/taskschd/task-scheduler-start-page) task) to run the command periodically.
Changes are validated and applyied dynamicly. A reload / restart is not nessesary.

## License

Expand Down
20 changes: 0 additions & 20 deletions config.yaml

This file was deleted.

52 changes: 52 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---

feeds:
github_user:
- binwiederhier
github_release:
- binwiederhier/ntfy
github_commit:
- binwiederhier/ntfy
- Kariton/rss-ntfy
pypi:
- ntfy
discuss_ntfy:
- c/ntfy
- u/binwiederhier
reddit_subreddit:
- SysadminHumor+Programmerhumor
- SelfHosted
- HomeLab
reddit_user:
- u/binwiederhier
youtube:
- name: UCXuqSBlHAE6Xw-yeJA0Tunw
feed_display_name: LTT

services:
github_user:
ntfy_topic: topic1

github_release:
ntfy_topic: topic2

github_commit:
ntfy_topic: topic3

pypi:
ntfy_topic: topic4

discuss_ntfy:
ntfy_topic: topic5

reddit_subreddit:
ntfy_topic: topic6

reddit_user:
ntfy_topic: topic7

youtube:
ntfy_topic: topic8

config:
run_on_startup: true
2 changes: 2 additions & 0 deletions docker-compose.yaml → docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
---
version: '3.8'

services:
rss-ntfy:
build:
context: .
volumes:
- ./config:/etc/rss-ntfy
- histfiles:/root/:rw

volumes:
Expand Down
7 changes: 5 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
bs4
feedparser
markdownify
jsonschema
watchdog
croniter
requests
lxml
pyyaml
Loading

0 comments on commit 2bc430f

Please sign in to comment.