Move remaining display-related code
This commit is contained in:
parent
6a36bc72e6
commit
aacd35d766
2 changed files with 19 additions and 20 deletions
22
sncf.ss
22
sncf.ss
|
@ -38,26 +38,10 @@
|
||||||
(get-station-id sncf-key station)
|
(get-station-id sncf-key station)
|
||||||
(values "Vernon - Giverny (Vernon)" "stop_area:SNCF:87415604")))
|
(values "Vernon - Giverny (Vernon)" "stop_area:SNCF:87415604")))
|
||||||
(let-values (((departures disruptions) (get-departures sncf-key station-id datetime)))
|
(let-values (((departures disruptions) (get-departures sncf-key station-id datetime)))
|
||||||
(display (parse-markup
|
(display-all departures disruptions station-name datetime)
|
||||||
(format "[bold]Prochains départs de [green]~a[/green] " station-name)))
|
|
||||||
(displayln (if datetime
|
|
||||||
(parse-markup (format "le ~a à ~a :"
|
|
||||||
(date->string datetime "~a ~d ~b ~Y")
|
|
||||||
(date->string datetime "~H:~M")))
|
|
||||||
":"))
|
|
||||||
(display-departures-table departures)
|
|
||||||
(display-disruptions disruptions)
|
|
||||||
(when mattermost-url
|
(when mattermost-url
|
||||||
(let ((tab-str-md (with-output-to-string
|
(let ((tab-str-md
|
||||||
(lambda ()
|
(with-output-to-string (lambda () (display-all departures disruptions station-name datetime)))))
|
||||||
(display (format "Prochains départs de **~a** " station-name))
|
|
||||||
(displayln (if datetime
|
|
||||||
(parse-markup (format "le ~a à ~a :\n"
|
|
||||||
(date->string datetime "~a ~d ~b ~Y")
|
|
||||||
(date->string datetime "~H:~M")))
|
|
||||||
":\n"))
|
|
||||||
(display-departures-table departures style: 'markdown)
|
|
||||||
(display-disruptions disruptions style: 'markdown)))))
|
|
||||||
(post-to-mattermost mattermost-url tab-str-md channel: mattermost-channel)))))
|
(post-to-mattermost mattermost-url tab-str-md channel: mattermost-channel)))))
|
||||||
(catch (getopt-error? exn)
|
(catch (getopt-error? exn)
|
||||||
(getopt-display-help exn "sncf" (current-error-port))
|
(getopt-display-help exn "sncf" (current-error-port))
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
(export display-departures-table
|
(export display-departures-table
|
||||||
display-disruptions)
|
display-disruptions
|
||||||
|
display-all)
|
||||||
|
|
||||||
(import :std/format
|
(import :std/format
|
||||||
:std/iter
|
:std/iter
|
||||||
|
@ -42,3 +43,17 @@
|
||||||
(let ((messages (hash-ref dis 'messages '())))
|
(let ((messages (hash-ref dis 'messages '())))
|
||||||
(display (if (eq? style 'markdown) "* " "• "))
|
(display (if (eq? style 'markdown) "* " "• "))
|
||||||
(displayln (if (null? messages) "[Pas de message]" (hash-ref (car messages) 'text))))))
|
(displayln (if (null? messages) "[Pas de message]" (hash-ref (car messages) 'text))))))
|
||||||
|
|
||||||
|
(def (display-all departures disruptions station-name (datetime #f) style: (style 'unicode))
|
||||||
|
(display
|
||||||
|
(if (eq? style 'markdown)
|
||||||
|
(format "Prochains départs de **~a** " station-name)
|
||||||
|
(parse-markup
|
||||||
|
(format "[bold]Prochains départs de [green]~a[/green] " station-name))))
|
||||||
|
(when datetime
|
||||||
|
(display (format "le ~a à ~a :"
|
||||||
|
(date->string datetime "~a ~d ~b ~Y")
|
||||||
|
(date->string datetime "~H:~M"))))
|
||||||
|
(displayln (if (eq? style 'markdown) ":\n" ":"))
|
||||||
|
(display-departures-table departures style: style)
|
||||||
|
(display-disruptions disruptions style: style))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue