Local Train Station Departures App

A desktop widget displaying upcoming train departures from your local station offers immediate convenience and significantly enhances daily productivity by allowing effortless planning around travel schedules. By providing real-time departure information at a glance, it ensures punctuality for future appointments, meetings, or personal engagements, reducing the stress associated with commuting uncertainties. The widget can also integrate seamlessly into customised desktop displays or broader smart-home dashboards, offering continuous, unobtrusive access to travel updates without interrupting workflow. This integration promotes a smoother, more efficient daily routine, saving valuable time and ensuring users remain consistently informed and prepared.

Key benefits and relevant use cases include:

  • Professional appointments: Quickly verifying departure times to avoid lateness or missed meetings.
  • Daily commuting: Minimising waiting times by timing departures accurately.
  • Home-working integration: Incorporating the widget into home-office setups to coordinate remote and in-office working days effectively.
  • Travel planning: Easy checking of upcoming departures to plan connecting journeys or onward travel.
  • Family scheduling: Coordinating family travel arrangements efficiently, particularly for school runs, social events, or leisure activities.
  • Accessibility considerations: Providing clear, instant transport updates to users with mobility issues or other accessibility requirements.
<!DOCTYPE html>
<html>
<head>
    <meta charset=\"UTF-8\">
    <title>Train Departures from Kings Cross</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background: #f9f9f9;
            padding: 20px;
        }
        h1 {
            font-size: 1.5em;
        }
        .train {
            padding: 10px;
            margin: 5px 0;
            border-bottom: 1px solid #ddd;
        }
    </style>
</head>
<body>
    <h1>Next 3 Departures from Kings Cross</h1>
    <div id=\"widget\">
        <?php
        // Replace with your actual API credentials
        $appId = 'YOUR ID';
        $appKey = 'YOUR API KEY';
        $stationCode = 'KGX';

        $url = \"https://transportapi.com/v3/uk/train/station/$stationCode/live.json?app_id=$appId&app_key=$appKey&darwin=false&train_status=passenger\";

        // Fetch data from TransportAPI
        $response = file_get_contents($url);
        
        if ($response === FALSE) {
            echo 'Error loading data.';
        } else {
            $data = json_decode($response, true);

            if (empty($data['departures']['all'])) {
                echo 'No train data available.';
            } else {
                $trains = array_slice($data['departures']['all'], 0, 3);

                foreach ($trains as $train) {
                    $destination = htmlspecialchars($train['destination_name'] ?? 'Unknown Destination');
                    $scheduled = htmlspecialchars($train['aimed_departure_time'] ?? 'TBA');
                    $estimated = htmlspecialchars($train['estimated_departure_time'] ?? $scheduled);
                    $platform = htmlspecialchars($train['platform'] ?? 'N/A');

                    echo \"
                        <div class=\\\"train\\\">
                            <strong>To: {$destination}</strong><br>
                            Scheduled: {$scheduled}<br>
                            Estimated: {$estimated}<br>
                            Platform: {$platform}
                        </div>
                    \";
                }
            }
        }
        ?>
    </div>
</body>
</html>