I am attempting to read and analyze GTFS-realtime data from the NYC subway in Python. So far, I have successfully used both gtfs-realtime.proto
and nyct-subway.proto
to generate the proper Python classes and parsed the protobuf data into Python objects.
My problem comes when trying to access certain fields in these objects. For example, the header (feed.header
) looks like this:
gtfs_realtime_version: "1.0"
incrementality: FULL_DATASET
timestamp: 1533111586
[nyct_feed_header] {
nyct_subway_version: "1.0"
trip_replacement_period {
route_id: "A"
replacement_period {
end: 1533113386
...
I can access the first three attributes using dot access, but not nyct_feed_header
. I suspect this is because it is part of the nyct-subway.proto
extension, while the other three are part of the original.
I have found this attribute accessible in feed.header.ListFields(), but since that returns a list of (name, attribute) pairs, it is at best awkward to access.
Why aren't attributes from extensions accessible by dot access like the rest of them? Is there a better or more elegant way to access them than by using ListFields?