Skip to content

Commit

Permalink
GTFS Alerts better support
Browse files Browse the repository at this point in the history
  • Loading branch information
jamespfennell committed Feb 14, 2020
1 parent 36b7bc7 commit 2294247
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docker/docker-compose.yml
Expand Up @@ -19,6 +19,8 @@ services:
- gunicorn
- -b
- 0.0.0.0:80
- -t
- "300"
- "transiter.http:wsgi_app"

scheduler:
Expand Down
15 changes: 8 additions & 7 deletions transiter/services/update/gtfsrealtimeparser.py
Expand Up @@ -42,7 +42,7 @@ def create_parser(gtfs_realtime_pb2_module=None, post_pb2_parsing_function=None)
# noinspection PyUnusedLocal
def parser(binary_content, *args, **kwargs):
gtfs_data = read_gtfs_realtime(binary_content, gtfs_realtime_pb2_module)
# print(json.dumps(gtfs_data))
# print(json.dumps(gtfs_data, indent=2))
if post_pb2_parsing_function is not None:
post_pb2_parsing_function(gtfs_data)
(feed_time, trips) = transform_to_transiter_structure(
Expand Down Expand Up @@ -185,6 +185,11 @@ def get_enum_value(enum, key, default):
alert_data = entity.get(ALERT)
if alert_id is None or alert_data is None:
continue
active_periods = alert_data.get(ACTIVE_PERIOD, {})
if len(active_periods) > 0:
first_active_period = active_periods[0]
else:
first_active_period = {}
alert = models.Alert(
id=alert_id,
cause=get_enum_value(
Expand All @@ -200,12 +205,8 @@ def get_enum_value(enum, key, default):
header=get_text(alert_data, HEADER_TEXT),
description=get_text(alert_data, DESCRIPTION_TEXT),
url=get_text(alert_data, URL),
start_time=self._timestamp_to_datetime(
alert_data.get(ACTIVE_PERIOD, {}).get(START)
),
end_time=self._timestamp_to_datetime(
alert_data.get(ACTIVE_PERIOD, {}).get(START)
),
start_time=self._timestamp_to_datetime(first_active_period.get(START)),
end_time=self._timestamp_to_datetime(first_active_period.get(END)),
)
informed_entities = alert_data.get(INFORMED_ENTITY, {})
alert.agency_ids = [
Expand Down

0 comments on commit 2294247

Please sign in to comment.