Hey, thanks for the amazingly quick response. Also, I’ve been seeing you answer a bunch of stuff I’ve looked up in the last couple days with some libraries, so thank you for all your work.
OK, I don’t mind triggering from the device. I am already doing that to send updates to my smarthome.
The API I want to hit is to grab a bus prediction. Sadly, the structure on these can change for no good reason, but I’ll deal with that when I get there. I did have some code running to parse the entire JSON down on the device, but that wasn’t efficient and it was hard to update.
Here’s an example of the JSON:
URL
http://webservices.nextbus.com/service/publicJSONFeed?command=predictionsForMultiStops&a=sf-muni&stops=N_OWL|6695&stops=N_OWL|7447
RESPONSE
{
"predictions":[
{
"message":[
{
"text":"Muni for essential trips only. Masks or face coverings are required. Practice physical distancing. Visit sfmta.com/COVID19 for more info.",
"priority":"Low"
},
{
"text":"Predictions may be unavailable. Buses every 30 minutes",
"priority":"Normal"
},
{
"text":"Text COVID19SF to 888-777 for official updates. Visit sfdph.org",
"priority":"Low"
}
],
"agencyTitle":"San Francisco Muni",
"routeTag":"N_OWL",
"routeTitle":"N-Owl",
"direction":{
"title":"Outbound to Ocean Beach",
"prediction":[
{
"isDeparture":"false",
"minutes":"13",
"seconds":"791",
"tripTag":"9341488",
"vehicle":"8660",
"affectedByLayover":"true",
"block":"9797",
"dirTag":"N____O_N00",
"epochTime":"1588674469947"
},
{
"isDeparture":"false",
"minutes":"43",
"seconds":"2591",
"tripTag":"9341490",
"vehicle":"8873",
"affectedByLayover":"true",
"block":"9799",
"dirTag":"N____O_N00",
"epochTime":"1588676269947"
},
{
"isDeparture":"false",
"minutes":"73",
"seconds":"4391",
"tripTag":"9341489",
"vehicle":"8887",
"affectedByLayover":"true",
"block":"9798",
"dirTag":"N____O_N00",
"epochTime":"1588678069947"
}
]
},
"stopTitle":"The Embarcadero & Brannan St",
"stopTag":"7447"
},
{
"message":[
{
"text":"Muni for essential trips only. Masks or face coverings are required. Practice physical distancing. Visit sfmta.com/COVID19 for more info.",
"priority":"Low"
},
{
"text":"Predictions may be unavailable. Buses every 30 minutes",
"priority":"Normal"
},
{
"text":"Text COVID19SF to 888-777 for official updates. Visit sfdph.org",
"priority":"Low"
}
],
"agencyTitle":"San Francisco Muni",
"routeTag":"N_OWL",
"routeTitle":"N-Owl",
"direction":{
"title":"Outbound to Ocean Beach",
"prediction":[
{
"isDeparture":"false",
"minutes":"9",
"seconds":"589",
"tripTag":"9341488",
"vehicle":"8660",
"affectedByLayover":"true",
"block":"9797",
"dirTag":"N____O_N00",
"epochTime":"1588674267679"
},
{
"isDeparture":"false",
"minutes":"39",
"seconds":"2389",
"tripTag":"9341490",
"vehicle":"8873",
"affectedByLayover":"true",
"block":"9799",
"dirTag":"N____O_N00",
"epochTime":"1588676067679"
},
{
"isDeparture":"false",
"minutes":"69",
"seconds":"4189",
"tripTag":"9341489",
"vehicle":"8887",
"affectedByLayover":"true",
"block":"9798",
"dirTag":"N____O_N00",
"epochTime":"1588677867679"
}
]
},
"stopTitle":"Townsend St & 4th St",
"stopTag":"6695"
}
],
"copyright":"All data copyright San Francisco Muni 2020."
}
What I want to get from this is going to be:
predictions[0].direction[0].prediction[0].seconds
and
predictions[1].direction[0].prediction[0].seconds
I am a little worried because I am not 100% sure that the seconds will be associated with the correct bus… that is, it might be that these come in different orders. Which means I might have to match one of the tags (routeTag=N_OWL) or direction. However, I believe that I can change the URL parameters so that I get a simplified version of this with just the route I want. But it would be nice to only have to set up one webhook to parse all the data… unless it’s easier to set up multiple hooks and handle them separately.
Lemme know if this is helpful. (XML is also available for this)