Sort Data by station name.

103 views
Skip to first unread message

Kevin

unread,
Mar 7, 2021, 4:19:41 PMMar 7
to mtadeveloperresources
Hello all,

I am quite new to this. Currently I have access and parse the live stream data from the ACE subway realtime feed endpoint. What I want to do is generate a list of all the trains arriving at station X. For example, let's say I want to use the 50th Street Subway station on 8th ave. How can I retrieve a list of all the trains arriving at this station regardless of if they are coming from the north or south?

My current understanding is that each 'entity' in 'feed.entity' is a certain train moving along somewhere in its path. So basically this is my code understanding:

for train in feed.entity:
     if train.stop_id ==  '50th Street Subway station':
           print(entity)

If there is any docs that could help me with this please let me know.

Thanks!
Kevin


JP Reardon

unread,
Mar 7, 2021, 7:12:01 PMMar 7
to mtadeveloperresources
You're on the right track. You can loop through tripUpdate.stopTimeUpdate to find the scheduled arrival and departure times for your station.

There's not much documentation (that I'm aware of) beyond what's on the MTA developer and Google GTFS site.

For me, looking through other people's code on github was a huge help. There are several projects using these feeds. You can see how I handle this situation starting on line 131 here, it's javascript, but I think you'll get the idea.

Good luck!

jp

James Fennell

unread,
Mar 7, 2021, 8:25:59 PMMar 7
to mtadevelop...@googlegroups.com
Just to add two small points to JP's answer:
- To get the stop ID of a particular station, you need to consult the GTFS Static feed. The 50th st station on the ACE line has ID A25, for example. The station has two platforms corresponding to the north and south direction with IDs A25N and A25S respectively - and these are the two IDs that will appear in the GTFS Realtime feed.
- Because of service changes, there may be trains at that 50th st station that are not in the ACE feed. As I write this, the F is stopping there. Theoretically to get the complete list of trains you need to search in each of the eight feeds...

James

--
You received this message because you are subscribed to the Google Groups "mtadeveloperresources" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mtadeveloperreso...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mtadeveloperresources/17027b2c-1c3e-495b-a8e6-962818e07d43n%40googlegroups.com.

Kevin

unread,
Mar 8, 2021, 12:45:15 AMMar 8
to mtadeveloperresources
Hey Guys,

Thanks for your help. I am still having a little trouble accessing the different attributes of feed.entity.trip_update.stop_time_update. How can I actually access the "stop_id" in this result (Python)?

Thanks!

Reply all
Reply to author
Forward
0 new messages