You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/usr/bin/env pythonfromdatetimeimportdatetimeimportrequestsfromgoogle.transitimportgtfs_realtime_pb2# Live vehicle position updates for every CapMetro vehicle 24/7CAPMETRO_URL='https://data.texas.gov/download/i5qp-g5fd/application/octet-stream'res=requests.get(CAPMETRO_URL)
feed=gtfs_realtime_pb2.FeedMessage()
feed.ParseFromString(res.content)
forentityinfeed.entity:
v=entity.vehicleifnotv.trip.route_id:
# vehicle is not in servicecontinuemsg='Vehicle {id} located at ({lat},{lon}) on route {route} at {timestamp}'printmsg.format(
id=v.vehicle.id,
lat=v.position.latitude,
lon=v.position.longitude,
route=v.trip.route_id,
timestamp=datetime.utcfromtimestamp(int(v.timestamp))
)
Example Output
Vehicle 2059 located at (30.2690181732,-97.7426528931) on route 486 at 2015-09-03 06:05:31
Vehicle 8910 located at (30.1877002716,-97.7631378174) on route 486 at 2015-09-03 06:03:56
Vehicle 8925 located at (30.2421226501,-97.7843856812) on route 484 at 2015-09-03 06:03:39
Vehicle 2233 located at (30.3545150757,-97.7041473389) on route 481 at 2015-09-03 06:03:56
Vehicle 8903 located at (30.2715206146,-97.7443313599) on route 481 at 2015-09-03 06:05:09
Vehicle 2206 located at (30.2705841064,-97.7136764526) on route 485 at 2015-09-03 06:04:38
Vehicle 8914 located at (30.3089466095,-97.7094345093) on route 485 at 2015-09-03 06:04:22
Vehicle 8926 located at (30.244020462,-97.7299880981) on route 20 at 2015-09-03 06:04:23
Vehicle 8918 located at (30.3164825439,-97.7321395874) on route 481 at 2015-09-03 06:04:48
Vehicle 2402 located at (30.2318382263,-97.7331848145) on route 483 at 2015-09-03 06:04:15