Basic search functionalty works!

This commit is contained in:
ronreg-ribdev 2020-06-05 04:09:57 -07:00
parent ed70fce6a7
commit bb0852ed97
2 changed files with 41 additions and 5 deletions

View File

@ -45,6 +45,7 @@ class ScheduleWidget extends Component {
} }
getSchedule(evt) { getSchedule(evt) {
console.log("Get schedule"); 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(); 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 { class RouteResults extends Component {
render() { render() {
const routes = this.props.routes;
console.log(this.props.routes); console.log(this.props.routes);
if (!this.props.routes) { if (!routes) {
return (<div></div>); 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> return (<div>
Trains: Trains:
<br/>
{ _.map(trips, (trip, idx) => <IndividualRouteResult key={idx} trip={trip} />) }
</div>); </div>);
} }
} }

View File

@ -188,13 +188,17 @@
(with-json-handler response handler) (with-json-handler response handler)
:: ::
++ bart-api-routeplan ++ bart-api-routeplan
:: Documentation: http://api.bart.gov/docs/sched/depart.aspx
|= [from=tape to=tape hour=@ min=@ ispm=?] |= [from=tape to=tape hour=@ min=@ ispm=?]
^- request:http ^- 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") =/ meridian ?:(ispm "pm" "am")
=/ time "{<hour>}:{<min>}{meridian}" =/ minstr ?: =(min 0) "00"
=/ url (crip "{bart-api-url-base}/sched.aspx?cmd=depart&orig={from}&dest={to}&time={time}&key={bart-api-key}&json=y") ?: (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>}" ~& "Making BART API request to {<url>}"
=/ headers [['Accept' 'application/json']]~ =/ headers [['Accept' 'application/json']]~
[%'GET' url headers *(unit octs)] [%'GET' url headers *(unit octs)]