Basic search functionalty works!
This commit is contained in:
parent
ed70fce6a7
commit
bb0852ed97
@ -45,6 +45,7 @@ class ScheduleWidget extends Component {
|
||||
}
|
||||
getSchedule(evt) {
|
||||
console.log("Get schedule");
|
||||
// Needs to make a request at https://www.bart.gov/schedules/bystationresults?station=12TH&date=06/03/2020&time=6%3A30%20PM
|
||||
evt.preventDefault();
|
||||
}
|
||||
|
||||
@ -251,15 +252,46 @@ class RouteSearch extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
class IndividualRouteResult extends Component {
|
||||
render() {
|
||||
const trip = this.props.trip;
|
||||
return (<div>
|
||||
Depart: {trip.depart} Arrive: {trip.arrive} ({trip.time})
|
||||
<br/>
|
||||
Cost: {trip.fare}
|
||||
<br/>
|
||||
Legs:
|
||||
{ _.map(trip.legs, (leg) => `${leg.line} line`) }
|
||||
</div>);
|
||||
}
|
||||
}
|
||||
|
||||
class RouteResults extends Component {
|
||||
render() {
|
||||
const routes = this.props.routes;
|
||||
console.log(this.props.routes);
|
||||
if (!this.props.routes) {
|
||||
if (!routes) {
|
||||
return (<div></div>);
|
||||
}
|
||||
|
||||
const request = routes.request;
|
||||
const trip = request.trip;
|
||||
const trips = _.map(trip, (t) => {
|
||||
return {
|
||||
fare: t['@fare'],
|
||||
depart: t['@origTimeMin'],
|
||||
arrive: t['@destTimeMin'],
|
||||
time: t['@tripTime'],
|
||||
legs: _.map(t.leg, (leg) => {
|
||||
return {line: leg['@trainHeadStation'] };
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
return (<div>
|
||||
Trains:
|
||||
<br/>
|
||||
{ _.map(trips, (trip, idx) => <IndividualRouteResult key={idx} trip={trip} />) }
|
||||
</div>);
|
||||
}
|
||||
}
|
||||
|
@ -188,13 +188,17 @@
|
||||
(with-json-handler response handler)
|
||||
::
|
||||
++ bart-api-routeplan
|
||||
:: Documentation: http://api.bart.gov/docs/sched/depart.aspx
|
||||
|= [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'
|
||||
=/ meridian ?:(ispm "pm" "am")
|
||||
=/ time "{<hour>}:{<min>}{meridian}"
|
||||
=/ url (crip "{bart-api-url-base}/sched.aspx?cmd=depart&orig={from}&dest={to}&time={time}&key={bart-api-key}&json=y")
|
||||
=/ minstr ?: =(min 0) "00"
|
||||
?: (lte min 9) "0{<min>}"
|
||||
"{<min>}"
|
||||
=/ time "{<hour>}:{minstr}{meridian}"
|
||||
=/ before 1
|
||||
=/ after 3
|
||||
=/ url (crip "{bart-api-url-base}/sched.aspx?cmd=depart&orig={from}&a={<after>}&b={<before>}&dest={to}&time={time}&key={bart-api-key}&json=y")
|
||||
~& "Making BART API request to {<url>}"
|
||||
=/ headers [['Accept' 'application/json']]~
|
||||
[%'GET' url headers *(unit octs)]
|
||||
|
Loading…
Reference in New Issue
Block a user