Skip to content

Commit

Permalink
feat: MultiGtfs checks if calendar & calendar_dates is missing & rais…
Browse files Browse the repository at this point in the history
…es. Otherwise create calendar table if missing.
  • Loading branch information
r-leyshon committed Jan 18, 2024
1 parent f93913b commit 8895d20
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/transport_performance/gtfs/multi_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
_check_parent_dir_exists,
_enforce_file_extension,
)
from transport_performance.gtfs.calendar import create_calendar_from_dates


class MultiGtfsInstance:
Expand Down Expand Up @@ -111,6 +112,25 @@ def __init__(self, path: Union[str, list, pathlib.Path]) -> None:
self.paths = path
# instantiate the GtfsInstance's
self.instances = [GtfsInstance(fpath) for fpath in path]
# ensure calendar is populated
for i, inst in enumerate(self.instances):
if inst.feed.calendar is None:
if inst.feed.calendar_dates is None:
raise FileNotFoundError(
"Both calendar and calendar_dates is empty for feed "
+ self.paths[i]
)
else:
warnings.warn(
f"No calendar found for {self.paths[i]}. Creating from"
" calendar dates"
)
# store calendar_dates
self.instances[
i
].feed.calendar = create_calendar_from_dates(
calendar_dates=inst.feed.calendar_dates
)

def save_feeds(self, dir: Union[pathlib.Path, str]) -> None:
"""Save the GtfsInstances to a directory.
Expand Down

0 comments on commit 8895d20

Please sign in to comment.