I’ve been using particle photons in a few projects so far and this forum has been great. For my next project, I wanted to build something similar to the following project that would tell me how many stops away my bus is in the morning by using the NYC MTA Bustime API:
I’m not quite sure how I would go about parsing the json data I get from my request in the cloud. Below is a sample of the request and resulting data:
Request:
I can make requests with my API key and get results in either json or xml ( http://bustime.mta.info/wiki/Developers/SIRIStopMonitoring)
For example, the below request gives me the results for two buses that are approaching the designated stop code 402205.
http://bustime.mta.info/api/siri/stop-monitoring.json?key=MY KEY&OperatorRef=MTA&MonitoringRef=402205&LineRef=MTA%20NYCT_M57&MaximumStopVisits=2
Data:
In the below data, I would like to be able to extract “StopsFromCall” for each of the two buses. This would tell me the number of stops away from stop code 402205 that each bus is.
{"Siri":{"ServiceDelivery":{"ResponseTimestamp":"2016-03-26T11:07:43.011-04:00","StopMonitoringDelivery":[{"MonitoredStopVisit":[{"MonitoredVehicleJourney":{"LineRef":"MTA NYCT_M57","DirectionRef":"0","FramedVehicleJourneyRef":{"DataFrameRef":"2016-03-26","DatedVehicleJourneyRef":"MTA NYCT_MQ_A6-Saturday-066300_M57_8"},"JourneyPatternRef":"MTA_M570093","PublishedLineName":"M57","OperatorRef":"MTA NYCT","OriginRef":"MTA_400751","DestinationRef":"MTA_903094","DestinationName":"EAST SIDE YORK - 60 ST XTOWN","SituationRef":[],"Monitored":true,"VehicleLocation":{"Longitude":-73.984209,"Latitude":40.779693},"Bearing":157.21857,"ProgressRate":"normalProgress","BlockRef":"MTA NYCT_MQ_A6-Saturday_A_MQ_21840_M57-2","VehicleRef":"MTA NYCT_3914","MonitoredCall":{"ExpectedArrivalTime":"2016-03-26T11:14:58.735-04:00","ExpectedDepartureTime":"2016-03-26T11:14:58.735-04:00","Extensions":{"Distances":{"PresentableDistance":"0.8 miles away","DistanceFromCall":1281.37,"StopsFromCall":6,"CallDistanceAlongRoute":1449.27}},"StopPointRef":"MTA_402205","VisitNumber":1,"StopPointName":"W 57 ST/11 AV"},"OnwardCalls":{}},"RecordedAtTime":"2016-03-26T11:07:22.000-04:00"},{"MonitoredVehicleJourney":{"LineRef":"MTA NYCT_M57","DirectionRef":"0","FramedVehicleJourneyRef":{"DataFrameRef":"2016-03-26","DatedVehicleJourneyRef":"MTA NYCT_MQ_A6-Saturday-067800_M57_11"},"JourneyPatternRef":"MTA_M570093","PublishedLineName":"M57","OperatorRef":"MTA NYCT","OriginRef":"MTA_400751","DestinationRef":"MTA_903094","DestinationName":"EAST SIDE YORK - 60 ST XTOWN","OriginAimedDepartureTime":"2016-03-26T11:18:00.000-04:00","SituationRef":[],"Monitored":true,"VehicleLocation":{"Longitude":-73.98418,"Latitude":40.779681},"Bearing":157.21857,"ProgressRate":"noProgress","ProgressStatus":"layover","BlockRef":"MTA NYCT_MQ_A6-Saturday_A_MQ_20040_M57-1","VehicleRef":"MTA NYCT_6737","MonitoredCall":{"ExpectedArrivalTime":"2016-03-26T11:14:53.396-04:00","ExpectedDepartureTime":"2016-03-26T11:14:53.396-04:00","Extensions":{"Distances":{"PresentableDistance":"0.8 miles away","DistanceFromCall":1284.12,"StopsFromCall":6,"CallDistanceAlongRoute":1449.27}},"StopPointRef":"MTA_402205","VisitNumber":1,"StopPointName":"W 57 ST/11 AV"},"OnwardCalls":{}},"RecordedAtTime":"2016-03-26T11:07:16.000-04:00"}],"ResponseTimestamp":"2016-03-26T11:07:43.011-04:00","ValidUntil":"2016-03-26T11:08:43.011-04:00"}],"SituationExchangeDelivery":[]}}}
I was hoping someone might be able to point me in the right direction on what my options are for parsing this data. I’m rather new at this sort of stuff and I’m learning as I go. I’d like it to be done in the cloud or on the particle photon if it is possible. I’d want to be able to refresh every 15-30 seconds or so. I was also thinking I could possibly run a python script on a raspberry pi to handle this but I was hoping to create a stand alone project.