diff --git a/src/js/components/root.js b/src/js/components/root.js index 6c5a4b4..f8efe3f 100644 --- a/src/js/components/root.js +++ b/src/js/components/root.js @@ -113,12 +113,14 @@ class RouteSearch extends Component { constructor(props) { super(props); const now = new Date(); + const hours = now.getHours(); this.state = { fromStation: "", toStation: "", depart: 'now', min: now.getMinutes(), - hour: now.getHours(), + hour: hours === 0 ? 12 : hours % 12, + isPM: hours >= 12 }; } @@ -134,7 +136,11 @@ class RouteSearch extends Component { evt.preventDefault(); api.action("bartinfo", "json", { from: this.state.fromStation, - to: this.state.toStation}); + to: this.state.toStation, + min: this.state.min, + hour: this.state.hour, + isPM: this.state.isPM, + }); } changeStation(evt) { @@ -155,10 +161,12 @@ class RouteSearch extends Component { setDepartAt(evt) { evt.preventDefault(); const now = new Date(); + const hours = now.getHours(); this.setState({ depart: "givenTime", - hour: now.getHours(), min: now.getMinutes(), + hour: hours === 0 ? 12 : hours % 12, + isPM: hours >= 12 }); } @@ -182,13 +190,30 @@ class RouteSearch extends Component {
- this.setState({hour: evt.target.value}) } disabled={departNow} + > + { _.map(_.range(1, 13), (hour) => { return ;}) } : - this.setState({min: evt.target.value}) } disabled={departNow} + > { _.map(_.range(0, 60), (min) => { return ;}) } + ); } diff --git a/urbit/app/bartinfo.hoon b/urbit/app/bartinfo.hoon index 405c74e..e7eecb1 100644 --- a/urbit/app/bartinfo.hoon +++ b/urbit/app/bartinfo.hoon @@ -105,12 +105,19 @@ ?> ?=(%o -.value) =/ update=json (pairs:enjs:format [update+o+p.value ~]) [%give %fact ~[/bartstations] %json !>(update)]~ -:: + :: [%elevators *] =/ value=json (parse-elevator-status-response:cc client-response.sign-arvo) ?> ?=(%o -.value) =/ update=json (pairs:enjs:format [update+o+p.value ~]) [%give %fact ~[/elevators] %json !>(update)]~ + :: + [%routeplan *] + ~& client-response.sign-arvo + =/ value=json (parse-routeplan-response:cc client-response.sign-arvo) + ?> ?=(%o -.value) + =/ update=json (pairs:enjs:format [update+o+p.value ~]) + [%give %fact ~[/routes] %json !>(update)]~ == [http-moves this] ?. ?=(%bound +<.sign-arvo) @@ -194,14 +201,20 @@ (with-json-handler response handler) :: ++ bart-api-routeplan - |= [from=tape to=tape] + |= [from=tape to=tape hour=@ min=@ ispm=?] ^- request:http :: http://api.bart.gov/api/sched.aspx?cmd=depart&orig=ASHB&dest=CIVC&date=now :: TODO cmd can be 'depart' or 'arrive', also 'fare' - =/ url (crip "{bart-api-url-base}/sched.aspx?cmd=depart&orig={from}&dest={to}&key={bart-api-key}&json=y") + =/ meridian ?:(ispm "pm" "am") + =/ time "{}:{}{meridian}" + =/ url (crip "{bart-api-url-base}/sched.aspx?cmd=depart&orig={from}&dest={to}&time={time}&key={bart-api-key}&json=y") ~& url =/ headers [['Accept' 'application/json']]~ [%'GET' url headers *(unit octs)] +++ parse-routeplan-response + |= response=client-response:iris + ^- json + (with-json-handler response |=(x=json x)) ++ poke-handle-json |= jon=json ^- (list card) @@ -209,15 +222,20 @@ =, format ?. ?=(%o -.jon) [~] - =/ omso ((om:dejs so:dejs) jon) - =/ from-station=tape (trip (~(gut by omso) 'from' '')) - =/ to-station=tape (trip (~(gut by omso) 'to' '')) - =/ req (bart-api-routeplan from-station to-station) + =/ [hour=@ min=@ ispm=? from-station=tape to-station=tape] + %. + jon + %: ot:dejs + ['hour' ni:dejs] + ['min' ni:dejs] + ['isPM' bo:dejs] + ['from' sa:dejs] + ['to' sa:dejs] + ~ + == + =/ req (bart-api-routeplan from-station to-station hour min ispm) =/ out *outbound-config:iris - =/ output [%pass /routeplan %arvo %i %request req out] -:: - =/ update=json *json - [%give %fact ~[/routes] %json !>(update)]~ + [[%pass /routeplan %arvo %i %request req out] ~] :: ++ poke-handle-http-request |= =inbound-request:eyre