This Python script fetches RSS feeds from multiple URLs and prints the title and link of each entry in the feed to the console. The method of sending emails is using the Mailjet API. For other mail services, changes will have to be made to the send_email
function.
- Python 3.x
Clone the repository or download the script file. To run the script, ensure you have the following modules installed:
- feedparser: Used to parse RSS feeds.
- requests: Used to make HTTP requests for fetching feeds and sending emails.
- pyyaml: Used to parse YAML configuration files.
- os: Standard library module for interacting with the operating system.
- logging: Standard library module for logging messages.
- time: Standard library module for working with time.
- json: Standard library module for working with JSON data.
- base64: Standard library module for encoding and decoding binary data in base64 format.
- bs4: A Python library for pulling data out of HTML and XML files. It works with your favorite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree.
- html: A standard library module in Python that provides utilities to manipulate HTML. It includes functions to escape and unescape HTML entities and convert characters to their HTML-safe sequences.
- datetime: Standard library module for manipulating dates and times.
You can install missing modules using pip, the Python package manager. For example:
pip install feedparser requests pyyaml bs4
Create a .env file in the same folder as the script with the structure below:
API_KEY: XXXXX
SECRET_KEY: XXXXX
SENDER_EMAIL: [email protected]
SENDER_EMAIL_NAME: "your sender name"
EMAIL_SUBJECT: "Put your email subject here"
RECEIVER_EMAILS:
- [email protected]
- [email protected]
RSS_URLS:
- feedURL1
- feedURL2
- feedURL3
Setup a venv in the folder where script is located
source /rss-feedfetcher/venv/bin/activate
pip install feedparser requests pyyaml bs4
deactivate
Create the service, with editor of your choice vim/nano/emacs
sudo vim /etc/systemd/system/rss-feedfetcher.service
Change the service folder /rss-feedfetcher/ to the folder where the script is
[Unit]
Description=RSS feed fetcher service
After=network.target
[Service]
WorkingDirectory=/rss-feedfetcher/
Environment="PATH=/rss-feedfetcher/venv/bin"
ExecStart=/rss-feedfetcher/venv/bin/python /rss-feedfetcher/rss-feedfetcher.py
[Install]
WantedBy=multi-user.target
Reload daemon to see newly created service
sudo systemctl daemon-reload
Enable the service to start on boot (after network is detected as specified in service)
sudo systemctl enable rss-feedfetcher.service
Start the service
sudo systemctl start rss-feedfetcher.service
Check status of service
sudo systemctl status rss-feedfetcher.service
- debugging
This project is licensed under the MIT License - see the LICENSE file for details.