From e6c92a3edfd64aeef0c4f41e92985abfda3155fd Mon Sep 17 00:00:00 2001 From: Christian Lawson-Perfect Date: Sun, 11 May 2025 09:09:38 +0000 Subject: [PATCH] Update every 30 seconds; adding a link to the station info page. --- cgi-bin/platform_data.py | 2 +- elm.json | 4 ++-- src/App.elm | 35 ++++++++++++++++++++++------------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/cgi-bin/platform_data.py b/cgi-bin/platform_data.py index b1a1c14..d721d0b 100755 --- a/cgi-bin/platform_data.py +++ b/cgi-bin/platform_data.py @@ -22,7 +22,7 @@ data_root.mkdir(exist_ok=True) fname = data_root / f'{station}-{platform}.json' -if (not fname.exists()) or (datetime.now() - datetime.fromtimestamp(fname.stat().st_mtime) > timedelta(minutes=1)): +if (not fname.exists()) or (datetime.now() - datetime.fromtimestamp(fname.stat().st_mtime) > timedelta(seconds=20)): req = requests.get(f'https://metro-rti.nexus.org.uk/api/times/{station}/{platform}') with open(fname, 'w') as f: f.write(req.text) diff --git a/elm.json b/elm.json index 3bcf1ee..18f95ae 100644 --- a/elm.json +++ b/elm.json @@ -11,10 +11,10 @@ "elm/html": "1.0.0", "elm/json": "1.1.3", "elm/svg": "1.0.1", - "elm/time": "1.0.0" + "elm/time": "1.0.0", + "elm/url": "1.0.0" }, "indirect": { - "elm/url": "1.0.0", "elm/virtual-dom": "1.0.3" } }, diff --git a/src/App.elm b/src/App.elm index c6589c5..f842b95 100644 --- a/src/App.elm +++ b/src/App.elm @@ -13,7 +13,8 @@ import Svg.Attributes as SA import Svg.Events as SE import Task import Time -import Tuple exposing (pair, first, second) +import Tuple exposing (pair, first, second) +import Url.Builder as UB port request_data : (String, Int) -> Cmd msg @@ -333,7 +334,7 @@ subscriptions model = Sub.batch [ receive_platform_data ReceivePlatformData , receive_location ReceiveLocation - , Time.every (1000 * 60) (\_ -> UpdatePlatformData) + , Time.every (1000 * 30) (\_ -> UpdatePlatformData) , Time.every 100 Tick , Browser.Events.onVisibilityChange VisibilityChange ] @@ -342,7 +343,7 @@ view : Model -> Browser.Document Msg view model = let current_station = model.current_station |> Maybe.map (station_with_key model) - + next_trains = current_station |> Maybe.map (\s -> @@ -354,16 +355,24 @@ view model = |> Maybe.withDefault "" view_station open station = - H.article - [ HE.on "toggle" ( - JD.succeed (TriggerTrainInfoRequest station) - ) - , HA.class "station" - ] - [ H.ol - [ HA.class "platforms"] - (List.map (view_platform station) station.platforms) - ] + let + info_url = UB.crossOrigin + "https://www.nexus.org.uk" + [ "metro/timetables-and-stations", station.name |> String.toLower |> String.replace " " "-" ] + [] + + in + H.article + [ HE.on "toggle" ( + JD.succeed (TriggerTrainInfoRequest station) + ) + , HA.class "station" + ] + [ H.ol + [ HA.class "platforms"] + (List.map (view_platform station) station.platforms) + , H.p [] [ H.a [ HA.href info_url, HA.target "station-info" ] [H.text <| "Station information for "++station.name]] + ] format_time t = let