From f1b75e7dae3355d9c4927964595fe9a95ea095e0 Mon Sep 17 00:00:00 2001 From: Dawid Pietrykowski Date: Thu, 13 Feb 2025 21:52:26 +0100 Subject: [PATCH] wip --- README.md | 9 +++++---- pyproject.toml | 10 ++++++++++ scripts/realtime.py | 22 ++++++++++++++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 pyproject.toml diff --git a/README.md b/README.md index f7542c9..90c8fae 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ ### API documentation -##### ZTM API - realtime data (delays / positions) +##### ZTM API docs https://www.ztm.poznan.pl/otwarte-dane/dla-deweloperow/ - -##### Poznan PCSS API - static timetables / trips -https://egov.psnc.pl/node/29#przystanki +##### ZTM API - static data (routes) + curl 'https://www.ztm.poznan.pl/pl/dla-deweloperow/getGTFSFile' -o routes.pb +##### ZTM API - realtime data (delays) + curl 'https://www.ztm.poznan.pl/pl/dla-deweloperow/getGtfsRtFile?file=trip_updates.pb' -o trip_updates.pb diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..94b19f6 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,10 @@ +[project] +name = "ha-poz-timetable" +version = "0.1.0" +description = "Poznan ZTM API integration" +readme = "README.md" +requires-python = ">=3.10" +dependencies = [ + "requests", + "gtfs-realtime-bindings" +] diff --git a/scripts/realtime.py b/scripts/realtime.py index 52cda8a..0d3b024 100755 --- a/scripts/realtime.py +++ b/scripts/realtime.py @@ -2,8 +2,22 @@ from google.transit import gtfs_realtime_pb2 import requests feed = gtfs_realtime_pb2.FeedMessage() -response = requests.get('https://www.ztm.poznan.pl/pl/dla-deweloperow/getGtfsRtFile?file=trip_updates.pb') -feed.ParseFromString(response.content) +# response = requests.get('https://www.ztm.poznan.pl/pl/dla-deweloperow/getGtfsRtFile?file=trip_updates.pb') +# response = '' +# with open('trip_updates.pb', 'rb') as f: +# response = f.read() +# feed.ParseFromString(response) +# for entity in feed.entity: +# print(entity) +# if entity.HasField('trip_update'): +# print(entity.trip_update) + + +with open('feeds.pb', 'rb') as f: + response = f.read() +feed = gtfs_realtime_pb2.FeedMessage() +feed.ParseFromString(response) for entity in feed.entity: - if entity.HasField('trip_update'): - print(entity.trip_update) + print(entity) + # if entity.HasField('trip_update'): + # print(entity.trip_update)