Last active
February 10, 2024 19:09
-
-
Save hansthen/0a918bb3321b159639875c6c463cbadc to your computer and use it in GitHub Desktop.
GTFS realtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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