Update every 30 seconds; adding a link to the station info page.

This commit is contained in:
Christian Lawson-Perfect 2025-05-11 09:09:38 +00:00
parent 3f68f9ae72
commit e6c92a3edf
3 changed files with 25 additions and 16 deletions

View file

@ -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)

View file

@ -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"
}
},

View file

@ -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