Skip to content
fernando.catalan
All projects

PersonalAutomation · Cloud

Train notifier with scheduled runs in the cloud

A Python script that queries the train operator's trip planner, picks the next services on my route, detects delay alerts and emails me. I first scheduled it with GitHub Actions and then migrated it to Azure Functions.

Role
Sole author
Period
Apr 2026
Status
Archived
Team
—

Context

A personal, educational project: I commute by train and wanted to know before leaving which services are coming and whether there are delays on my stretch, without opening the site every morning and every evening.

The problem

The operator's site sends no notifications: you have to open it, choose origin and destination and read the timetable.

Its alerts also cover the whole network, and most do not affect your own stretch. A notification that fires every day about delays elsewhere in the country stops being read.

What I built

  • A scraper built on requests and BeautifulSoup that queries the planner with origin, destination, date and passenger type, and extracts departure, arrival, duration and price for each train.

  • A moving window: only trains leaving between run time and two hours later, with one route for the morning and another for the evening.

  • An alert filter by geographic relevance, which drops notices that only mention other parts of the country.

  • An HTML email with the list of trains and, when relevant, an alert block.

  • Five small modules (scraping, rules, configuration, email and orchestration), with credentials, routes and passenger type in environment variables and a template so anyone can adapt it to their own stations.

  • Scheduled runs Monday to Friday: first with two crons in GitHub Actions and then as an Azure Functions app with two timer triggers, deployed from GitHub Actions with federated identity (OIDC).

Architecture

architecture.svgSwipe →
  • CI/CD
  • Compute
  • External system
  • Managed service
  • Trigger:
    • GitHub Actions: cron · Monday to Friday
    • Azure Functions: 2 timer triggers
  • Script:
    • Python notifier: 5 modules
  • Outside:
    • Trip planner: operator's HTML
    • Email: SMTP · HTML

Connections:

  • GitHub Actions → Python notifier
  • Azure Functions → Python notifier
  • Trip planner → Python notifier (timetable · alerts)
  • Python notifier → Email

Technical decisions

  1. Keeping scraping, rules and notification apart

    Scraping lives in one module, the rules (time window and alert filter) in another and delivery in a third. If the site's HTML changes, the fix stays confined to the first.

  2. The same code, two ways to schedule it

    It began as a workflow with two crons and the sensitive values in repository secrets. The move to Azure Functions wrapped the same function in two timer triggers of the Python v2 programming model, without touching the logic.

Stack

Code
  • Python 3
  • requests
  • BeautifulSoup 4
  • smtplib
Runtime
  • GitHub Actions
  • Azure Functions
  • OIDC

Outcome

  • Seven successful runs on GitHub Actions, scheduled and manual, between April 23 and 28, 2026.

  • Migrated and deployed to Azure Functions on April 28, 2026, with deployment automated from GitHub Actions.

  • 337 lines of Python in five modules, with a README, a configuration template, an MIT license and a disclaimer.

What I learned

  • Scheduling a cron in GitHub Actions means translating Chilean time into UTC.

  • Taking a script serverless with Azure Functions: timer triggers, host.json and the Python v2 programming model.

  • Deploying to Azure from GitHub Actions with federated identity (OIDC), with no deployment password stored.

  • Documenting a project for others: README, variable template, license and disclaimer.