* .pb 파일을 읽어야합니다. 이 파이썬 라이브러리 https://github.com/google/gtfs-realtime-bindings은 .pb 파일을 사람이 읽을 수있는 형식으로 구문 분석 할 수있는 것으로 보입니다. 또한 개체를 다시 이진 형식으로 serialize 할 수 있습니다. pb파이썬에서 GTFS-RT protobuf 메시지 반복 및 편집
내 문제는 메시지를 탐색하기가 어렵다는 것입니다.
내가 같은로드 :
feed = gtfs_realtime_pb2.FeedMessage()
response = requests.get(url)
feed.ParseFromString(response.content)
message=feed.entity
for item in message:
if item.id==trip_id:
if item.HasField('trip_update'):
#do something with the item's fields
나는 두 가지 문제가 있습니다 내가 "trip_update"에 포함 된 서브 필드를 반복하고 또한 values.Specifically을 변경하려면, 내부 stop_time_updates의 숫자가있다 나는 변화시키고 싶다. 그래서
id: "61443658"
trip_update {
trip {
trip_id: "61443658"
start_time: "16:19:00"
start_date: "20171027"
schedule_relationship: SCHEDULED
route_id: "17529"
direction_id: 0
}
stop_time_update {
departure {
delay: 0
time: 1509113940
}
stop_id: "54376"
schedule_relationship: SCHEDULED
}
stop_time_update {
arrival {
delay: 0
time: 1509114240
}
departure {
delay: 0
time: 1509114240
}
stop_id: "54633"
schedule_relationship: SCHEDULED
처럼
는 그 후, 나는 단순히 파일을 직렬화. 이 피드 엔티티 개체를 탐색하는 데 사용할 수있는 방법이없는 것 같습니다. 위의 작업을 수행 할 수있는 방법이 있다면 놓친 것입니다. 알려 주시면 감사하겠습니다. 올바른 방향으로 올바른 도구를 지정해 주시면 감사하겠습니다.
환호
만약 사용한다면, 아마도 StopTimeUpdates를 반복하고, 사용 된 gtfs 실시간 항아리에 대한 링크를 찾을 수있는 Java 예제를 제공 할 수 있습니다 – paulh