A Python script that fetches energy drink offers from major German cities, filters them by popular supermarkets, and sends a neatly formatted overview to a Telegram chat. The script includes blacklist filtering, random energy drink facts, and automatic message pinning in Telegram groups.
- City-based filtering: Fetch offers from major German cities like Berlin, Hamburg, Munich, and more.
- Blacklist support: Exclude unwanted products such as batteries or specific brands.
- Random energy drink facts: Display a fun fact with each message.
- HTML-formatted messages: Clean, readable messages with bold, italics, and emojis.
- Automatic message pinning: Pins the last sent message in Telegram groups.
- Long message handling: Automatically splits long messages into chunks to meet Telegram's 4096-character limit.
- City-based Offer Fetching: The script pulls energy drink offers from various cities across Germany, filtering out irrelevant products and organizing them by city.
- Blacklist: Products containing blacklisted terms (stored in
blacklist.json
) are filtered out of the final results. - Random Energy Drink Facts: At the end of the message, the bot sends a random energy drink fact (stored in
facts.json
). - Automatic Message Pinning: After sending the message to the Telegram chat, the bot automatically pins the last message in the chat.
- Python 3.x: Make sure you have Python installed. You can download it here.
- Pip: Python’s package installer (usually comes pre-installed with Python).
- Telegram Bot: You need a Telegram bot token, which you can obtain from BotFather.
-
Clone the repository:
git clone https://github.com/yourusername/energy-drink-offers-bot.git cd energy-drink-offers-bot
-
Install the required dependencies:
Create a virtual environment (optional but recommended):
python3 -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate
Install the required Python packages:
pip install -r requirements.txt
-
Set up your
config.ini
:Copy the provided
config.ini
template:cp config.ini.example config.ini
Open
config.ini
and add your Telegram bot token and chat ID: (You can leave api shit empty, the script gets that data itself after first run)[Telegram] bot_token = your_telegram_bot_token chat_id = your_chat_id [API] x_apikey = x_clientkey =
-
Blacklist setup:
Create a
blacklist.json
file to exclude certain products:{ "blacklisted_terms": ["batterie", "akku", "l'oréal", "hydra"] }
-
Facts setup:
Add some energy drink facts to
facts.json
:{ "facts": [ "Red Bull was the first energy drink to become globally known.", "Energy drinks can improve focus and reaction times." ] }
-
Run the script:
To run the bot, use the following command:
python energy_drink_offers.py
To automate the running of the script at specific intervals (e.g., weekly), you can set up a cron job. Follow these steps:
-
Open your crontab:
crontab -e
-
Add the cron job:
Here’s an example to run the script every Monday at 4:20 AM:
20 4 * * 1 /path/to/your/venv/bin/python /path/to/your/repo/energy_drink_offers.py >> /path/to/your/repo/logs/output.log 2>&1
- Replace
/path/to/your/venv/bin/python
with the path to your virtual environment's Python binary. - Replace
/path/to/your/repo
with the path to where the script is stored. - The output will be logged in
logs/output.log
.
- Replace
-
Save and exit.
Feel free to fork this repository, open issues, or submit pull requests for any feature enhancements or bug fixes.
This project is licensed under the MIT License.