This Python script is designed to scrape and post items from a Finnish online marketplace (https://www.tori.fi) to a specified Telegram user. It includes features such as log file rotation and customizable settings for item posting time frame and script execution intervals.
- Automated Web Scraping: Retrieves item details from a specific URL.
- Telegram Notifications: Sends item updates to a Telegram user.
- Configurable Time Frame and Sleep Interval: Customizable settings for item posting time frame and execution intervals.
- Log File Rotation: Automatically manages log file sizes, rotating them when they exceed a specified size.
- Continuous Operation: Designed to run continuously in the background.
- Python 3.6 or later.
- PIP for package installation.
To receive notifications, you need to create a Telegram bot and obtain a token:
- Open Telegram and search for 'BotFather'.
- Start a conversation with BotFather and create a new bot by sending
/newbot
. - Follow the instructions to name your bot and get a username.
- BotFather will provide a token. Copy this token.
- Find your Telegram user ID by messaging
@userinfobot
. - Create a
.env
file in the project directory with the following content:TELEGRAM_TOKEN=your_telegram_bot_token USER_ID=your_telegram_user_id LOG_LEVEL=DEBUG_or_INFO SLEEP_INTERVAL=define_seconds
-
Clone the Repository (if applicable):
git clone [repository-url] cd [repository-directory]
-
Install Dependencies:
pip3 install -r requirements.txt
-
Environment Setup: Create a
.env
file with the following content:TELEGRAM_TOKEN=your_telegram_bot_token USER_ID=your_telegram_user_id LOG_LEVEL=DEBUG # Can be INFO, WARNING, ERROR, CRITICAL SLEEP_INTERVAL=120 # Time in seconds for script sleep interval
Execute the script using the following command:
nohup python3 tori2telegram.py > tori2telegram.log 2>&1 &
This command runs the script in the background, detaching it from the terminal, and logs output to tori2telegram.log
.
To stop the running script:
-
Find the Process ID (PID):
ps -ef | grep tori2telegram.py
-
Terminate the Process:
kill [PID]
Replace
[PID]
with the actual process ID.
TIME_FRAME_MINUTES
: Set within the script to define the window for considering new items.
SLEEP_INTERVAL
: Defined in the.env
file, this variable sets the pause duration (in seconds) between execution cycles.
- The script includes functionality to automatically rotate the log file
tori2telegram.log
when it reaches a specified size limit, keeping the log management efficient.
- Adjust the sleep interval with caution to avoid server rate-limiting or high resource consumption.
This script is designed for personal, non-commercial use only. It functions by notifying the user about new listings on Tori.fi, sending direct links (not the content) to a specified personal Telegram account. Users should be aware that this script must be used in compliance with the terms of service of Tori.fi, and any applicable data protection and privacy laws. The script does not create a database or redistribute content from Tori.fi. Users are responsible for ensuring that their use of the script aligns with all legal and regulatory requirements. This tool is not endorsed by or affiliated with Tori.fi or Telegram. For any concerns or questions about legal compliance, users are encouraged to consult with a legal professional.