Skip to content

Instantly share code, notes, and snippets.

@hansthen
Last active February 10, 2024 19:09
Show Gist options
  • Save hansthen/0a918bb3321b159639875c6c463cbadc to your computer and use it in GitHub Desktop.
Save hansthen/0a918bb3321b159639875c6c463cbadc to your computer and use it in GitHub Desktop.
GTFS realtime
import gtfs_realtime_OVapi_pb2 as ovapi
import requests
import urllib.request
from datetime import datetime
import time
from google.protobuf.json_format import MessageToJson, MessageToDict
from IPython import embed
feed = ovapi.gtfs__realtime__pb2.FeedMessage()
pb_url = "https://gtfs.openov.nl/gtfs-rt/vehiclePositions.pb"
while True:
try:
with urllib.request.urlopen(pb_url) as resp:
feed.ParseFromString(resp.read())
#print(feed.header)
d = MessageToJson(feed)
#print(d["header"],
# datetime.fromtimestamp(int(d["header"]["timestamp"])))
print(d)
except Exception as e:
print("Error", e)
time.sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment