Script is designed to check if a file is available at a specified URL and send an email notification if the file is found. It is mandatory to know the exact URL of a file. For example, I used it for student scholarship application results since it's location followed a specific pattern.
Open the config.inifile and fill it out with your details. Below is a sample configuration:
[SMTP]
server = smtp.gmail.com # SMTP server for sending emails
port = 587 # Port for SMTP server
email = YOUR_EMAIL # Your email address (used for sending notifications)
password = YOUR_PASSWORD # Your email password or app-specific password
[URL]
file_path = url.txt # Path to a file containing the URL to be monitored
[RECIPIENT]
email = RECIPIENT_EMAIL # Email address where notifications will be sent
subject = File Found! # Subject of the notification email
body = The file is available at: # Email body prefixImportant: For Gmail, you have to use app-specific password if two factor authentication is enabled.
Note: URLs are stored in url.txt because certain URLs (e.g those in Serbian Cyrilic) may not parse corectly when included in config.ini file.
To make the script run periodically, you need to set up a task scheaduler based on your operating system:
- Windows: Use Task Scheduler. Create a new task and configure it to run the script (
.pyfile) at your desired interval. - Linux: Use
cron. Open the crontab withcrontab -eand add a line like this to scheadule the script:
*/30 * * * * /usr/bin/python3 /path/to/script.py