Update every 30 seconds; adding a link to the station info page.
This commit is contained in:
parent
3f68f9ae72
commit
e6c92a3edf
3 changed files with 25 additions and 16 deletions
|
@ -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)
|
||||
|
|
4
elm.json
4
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"
|
||||
}
|
||||
},
|
||||
|
|
11
src/App.elm
11
src/App.elm
|
@ -14,6 +14,7 @@ import Svg.Events as SE
|
|||
import Task
|
||||
import Time
|
||||
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
|
||||
]
|
||||
|
@ -354,6 +355,13 @@ view model =
|
|||
|> Maybe.withDefault ""
|
||||
|
||||
view_station open station =
|
||||
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)
|
||||
|
@ -363,6 +371,7 @@ view model =
|
|||
[ 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 =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue