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'
|
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}')
|
req = requests.get(f'https://metro-rti.nexus.org.uk/api/times/{station}/{platform}')
|
||||||
with open(fname, 'w') as f:
|
with open(fname, 'w') as f:
|
||||||
f.write(req.text)
|
f.write(req.text)
|
||||||
|
|
4
elm.json
4
elm.json
|
@ -11,10 +11,10 @@
|
||||||
"elm/html": "1.0.0",
|
"elm/html": "1.0.0",
|
||||||
"elm/json": "1.1.3",
|
"elm/json": "1.1.3",
|
||||||
"elm/svg": "1.0.1",
|
"elm/svg": "1.0.1",
|
||||||
"elm/time": "1.0.0"
|
"elm/time": "1.0.0",
|
||||||
|
"elm/url": "1.0.0"
|
||||||
},
|
},
|
||||||
"indirect": {
|
"indirect": {
|
||||||
"elm/url": "1.0.0",
|
|
||||||
"elm/virtual-dom": "1.0.3"
|
"elm/virtual-dom": "1.0.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
35
src/App.elm
35
src/App.elm
|
@ -13,7 +13,8 @@ import Svg.Attributes as SA
|
||||||
import Svg.Events as SE
|
import Svg.Events as SE
|
||||||
import Task
|
import Task
|
||||||
import Time
|
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
|
port request_data : (String, Int) -> Cmd msg
|
||||||
|
@ -333,7 +334,7 @@ subscriptions model =
|
||||||
Sub.batch
|
Sub.batch
|
||||||
[ receive_platform_data ReceivePlatformData
|
[ receive_platform_data ReceivePlatformData
|
||||||
, receive_location ReceiveLocation
|
, receive_location ReceiveLocation
|
||||||
, Time.every (1000 * 60) (\_ -> UpdatePlatformData)
|
, Time.every (1000 * 30) (\_ -> UpdatePlatformData)
|
||||||
, Time.every 100 Tick
|
, Time.every 100 Tick
|
||||||
, Browser.Events.onVisibilityChange VisibilityChange
|
, Browser.Events.onVisibilityChange VisibilityChange
|
||||||
]
|
]
|
||||||
|
@ -342,7 +343,7 @@ view : Model -> Browser.Document Msg
|
||||||
view model =
|
view model =
|
||||||
let
|
let
|
||||||
current_station = model.current_station |> Maybe.map (station_with_key model)
|
current_station = model.current_station |> Maybe.map (station_with_key model)
|
||||||
|
|
||||||
next_trains =
|
next_trains =
|
||||||
current_station
|
current_station
|
||||||
|> Maybe.map (\s ->
|
|> Maybe.map (\s ->
|
||||||
|
@ -354,16 +355,24 @@ view model =
|
||||||
|> Maybe.withDefault ""
|
|> Maybe.withDefault ""
|
||||||
|
|
||||||
view_station open station =
|
view_station open station =
|
||||||
H.article
|
let
|
||||||
[ HE.on "toggle" (
|
info_url = UB.crossOrigin
|
||||||
JD.succeed (TriggerTrainInfoRequest station)
|
"https://www.nexus.org.uk"
|
||||||
)
|
[ "metro/timetables-and-stations", station.name |> String.toLower |> String.replace " " "-" ]
|
||||||
, HA.class "station"
|
[]
|
||||||
]
|
|
||||||
[ H.ol
|
in
|
||||||
[ HA.class "platforms"]
|
H.article
|
||||||
(List.map (view_platform station) station.platforms)
|
[ 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 =
|
format_time t =
|
||||||
let
|
let
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue