This Python script monitors JavaScript files or HTML pages for changes and sends updates to a Telegram chat. It can detect new or removed JavaScript files from URLs and send a log of the changes to Telegram.
- Monitors JavaScript files in URLs for changes.
- Sends notifications about added or removed JavaScript files via Telegram.
- Periodically checks for updates based on a configurable interval.
- Supports both file and URL monitoring.
- Sends logs to Telegram with details of the changes.
- Python 3.8+
- External Libraries:
requestspython-dotenvargparse
Install dependencies via pip:
pip install requests python-dotenv-
Telegram Setup: You will need a Telegram bot and a chat ID to receive the messages.
- Create a new Telegram bot via BotFather.
- Get your Telegram chat ID. (You can find this by using a bot like @userinfobot to get your chat ID.)
-
Environment Variables: Create a
.envfile in the project directory and add your bot credentials:TELEGRAM_BOT_TOKEN=<your_telegram_bot_token> TELEGRAM_CHAT_ID=<your_telegram_chat_id>
-
Configuration File: Create a configuration file (e.g.,
config.txt) to list the URLs or files you want to monitor. Each item should be listed on a new line:Example
config.txt:https://example.com https://example.com/page.html -
Run the Script: You can run the script with the following command:
python changes.py -c config.txt -t 60 --jjs
Arguments:
-cor--config: The path to the configuration file.-tor--interval: Time interval (in seconds) between checks (default: 60).--jjs: If set, the script will extract and monitor JavaScript files in the HTML content of the URLs.
-
Extract JavaScript Files: If the
--jjsflag is used, the script extracts JavaScript files from the HTML content of the provided URLs. -
Monitor for Changes: The script monitors for changes by comparing the previously fetched JavaScript files with the new ones. It detects additions and removals.
-
Telegram Notifications: When a change is detected, the script generates a log and sends it to your Telegram chat as a document.
-
Log File: The log file is generated dynamically, showing the changes with timestamps.
For example, if a new JavaScript file is added or an existing one is removed, the log will look like this:
2025-01-11 12:00:00 https://example.com
[+] line 10: /scripts/new_file.js
[-] line 15: /scripts/old_file.js
[!] Finished
The log will be sent as a document to your Telegram chat.
This project is licensed under the MIT License.