Check for new train schedules on the Ferrocarril Central Andino line from Lima to Huancayo
Find a file
2025-02-21 17:17:44 -05:00
sample Initial commit. 2025-02-21 16:52:09 -05:00
.gitignore Add .gitignore file. 2025-02-21 16:58:32 -05:00
check.py Include URL in new dates found mail. 2025-02-21 17:17:44 -05:00
README.md Add README.md 2025-02-21 17:08:48 -05:00

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.

Installation

  1. Clone the Repository:

    git clone https://git.4angle.com/edward/ferrocarrilcentral.git
    cd ferrocarrilcentral
    
  2. Install Dependencies: Requires Python 3 and the following packages:

    pip install requests lxml
    
  3. 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

  1. 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
    
  2. Data Storage:

    • Previously seen dates are stored in ~/lib/data/ferrocarril_dates.json.
    • The script creates this file automatically on the first successful run.

How It Works

  1. Fetches the webpage from https://ferrocarrilcentral.com.pe/appfcca/.
  2. Parses available travel dates using lxml.html.
  3. Compares against dates in ~/lib/data/ferrocarril_dates.json.
  4. Sends an email if new dates are found and updates the JSON file.

Requirements

  • Python 3.6+
  • requests library for HTTP requests
  • lxml library for HTML parsing
  • An SMTP server for email notifications

License

This project is licensed under the MIT License.