Skip to content

Commit

Permalink
fix: add country code, bump patch version
Browse files Browse the repository at this point in the history
  • Loading branch information
machow committed Apr 20, 2021
1 parent f3c5187 commit 4eb8aeb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,12 @@ docker-compose run gtfs-validator /bin/bash
# then, run example script in container
gtfs-validator-api validate tests/sample.zip
gtfs-validator-api validate --help
gtfs-validator-api validate-gcs-bucket \
-v -r \
-o validation.json \
cal-itp-data-infra \
google_default \
gs://gtfs-data-test/schedule/2021-03-28T00:00:00+00:00
```

12 changes: 7 additions & 5 deletions gtfs_validator_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.0.1"
__version__ = "0.0.5"

import os
import json
Expand All @@ -20,7 +20,7 @@
# API ----

@arg("gtfs_file", help="a zipped gtfs file", type=str)
def validate(gtfs_file, out_file=None, verbose=False):
def validate(gtfs_file, out_file=None, verbose=False, feed_name="us-na"):
if not isinstance(gtfs_file, str):
raise NotImplementedError("gtfs_file must be a string")

Expand All @@ -35,7 +35,7 @@ def validate(gtfs_file, out_file=None, verbose=False):
"-jar", JAR_PATH,
"--input", gtfs_file,
"--output_base", tmp_out_dir,
"--feed_name", "na-na",
"--feed_name", feed_name,
], stderr=stderr, stdout=stdout)

report = Path(tmp_out_dir) / "report.json"
Expand Down Expand Up @@ -68,7 +68,7 @@ def validate_many(gtfs_files, out_file=None, verbose=False):

def _get_paths_from_status(f, bucket_path):
from csv import DictReader
tmpl_path = "{bucket_path}/{itp_id}/{url_number}/"
tmpl_path = "{bucket_path}/{itp_id}_{url_number}/"

rows = list(DictReader(f))

Expand All @@ -85,13 +85,15 @@ def _get_paths_from_status(f, bucket_path):
@arg("bucket_paths", nargs="+")
def validate_gcs_bucket(
project_id, token, bucket_paths,
feed_name="us-na",
recursive=False, out_file=None, verbose=False
):
"""
Arguments:
project_id: name of google cloud project
token: token argument passed to gcsfs.GCSFileSystem
bucket_paths: list-like. paths to gcs buckets (e.g. gs://a_bucket/b/c)
feed_name: a string of form "{iso_country}-{custom_name}"
recursive: whether to look for a file named status.csv in bucket, and
use that to validate multiple gtfs data sources within.
out_file: file path for saving json result (may be a bucket)
Expand Down Expand Up @@ -129,7 +131,7 @@ def validate_gcs_bucket(

result = {
"version": os.environ["GTFS_VALIDATOR_VERSION"],
"data": validate(path_zip, verbose=verbose)
"data": validate(path_zip, verbose=verbose, feed_name=feed_name)
}

results.append(result)
Expand Down

0 comments on commit 4eb8aeb

Please sign in to comment.