sample | ||
.gitignore | ||
check.py | ||
README.md |
Ferrocarril Central Monitor
Check for new train schedules on the Ferrocarril Central Andino line from Lima to Huancayo.
This script monitors the Ferrocarril Central Andino website (https://ferrocarrilcentral.com.pe/appfcca/
) for available travel dates, compares them against previously seen dates, and sends an email notification when new dates are detected. Designed to run as a cron job for automated daily checks.
- Author: Edward Betts
- Email: edward@4angle.com
- Repository: https://git.4angle.com/edward/ferrocarrilcentral
- License: MIT
Installation
-
Clone the Repository:
git clone https://git.4angle.com/edward/ferrocarrilcentral.git cd ferrocarrilcentral
-
Install Dependencies: Requires Python 3 and the following packages:
pip install requests lxml
-
Make Executable:
chmod +x check.py
Usage
Run the script manually to test:
./check.py
For automated monitoring, add it to your crontab to run twice daily (e.g., 8 AM and 8 PM):
crontab -e
Add this line:
0 8,20 * * * /home/edward/src/ferrocarrilcentral/check.py
- Interactive Mode: Outputs informational messages (e.g., "New dates found") to stdout.
- Cron Mode: Silent unless errors occur, which are logged to stdout (captured by cron).
Configuration
-
Config File: Create
~/.config/ferrocarril/config
(INI format) with your SMTP settings:[mail] smtp_host = your.smtp.server from_address = your.email@example.com to_address = recipient@example.com
-
Data Storage:
- Previously seen dates are stored in
~/lib/data/ferrocarril_dates.json
. - The script creates this file automatically on the first successful run.
- Previously seen dates are stored in
How It Works
- Fetches the webpage from
https://ferrocarrilcentral.com.pe/appfcca/
. - Parses available travel dates using
lxml.html
. - Compares against dates in
~/lib/data/ferrocarril_dates.json
. - Sends an email if new dates are found and updates the JSON file.
Requirements
- Python 3.6+
requests
library for HTTP requestslxml
library for HTML parsing- An SMTP server for email notifications
License
This project is licensed under the MIT License.