diff --git a/gtfsrthttp2mqtt.py b/gtfsrthttp2mqtt.py index 56be14a..35b8cd3 100644 --- a/gtfsrthttp2mqtt.py +++ b/gtfsrthttp2mqtt.py @@ -111,11 +111,12 @@ def doGTFSRTPolling(self): vehicle_id = entity.vehicle.vehicle.id short_name = utils.parse_short_name(self.feedName, trip_id, route_id, self.OTPData) color = utils.parse_color(self.feedName, trip_id, route_id, self.OTPData) + mode = utils.parse_mode(self.feedName, trip_id, route_id, self.OTPData) # gtfsrt/vp////////////////// # GTFS RT feed used for testing was missing some information so those are empty - full_topic = '{0}/{1}////{2}/{3}/{4}/{5}/{6}/{7}/{8}/{9}/{10}/{11}/{12}/{13}/{14}/'.format( - self.baseMqttTopic, self.feedName, route_id, direction_id, + full_topic = '{0}/{1}///{2}/{3}/{4}/{5}/{6}/{7}/{8}/{9}/{10}/{11}/{12}/{13}/{14}/{15}/'.format( + self.baseMqttTopic, self.feedName, mode, route_id, direction_id, trip_headsign, trip_id, stop_id, start_time, vehicle_id, geohash_head, geohash_firstdeg, geohash_seconddeg, geohash_thirddeg, short_name, color) diff --git a/utils.py b/utils.py index bc91664..69b1697 100644 --- a/utils.py +++ b/utils.py @@ -47,6 +47,20 @@ def parse_color(feed, trip_id, route_id, otp_data): return "" return otp_data[feed + ":" + route_id]["color"] or "" +def parse_mode(feed, trip_id, route_id, otp_data): + if otp_data == None: + return "" + elif feed == "OULU": + feed_scoped_id = "OULU:" + trip_id + if feed_scoped_id not in otp_data: + return "" + return otp_data[feed_scoped_id]["route"]["mode"] or "" + + feed_scoped_id = feed + ":" + route_id + if feed_scoped_id not in otp_data: + return "" + return otp_data[feed + ":" + route_id]["mode"] or "" + def get_OTP_query(feed): if feed == "OULU": return """ @@ -56,6 +70,7 @@ def get_OTP_query(feed): shortName gtfsId color + mode } gtfsId pattern { @@ -71,6 +86,7 @@ def get_OTP_query(feed): gtfsId shortName color + mode } } """ % feed