示例#1
0
def read_to_dict_schedule_and_stopd_db(path: str, day: str):
    if persistence.is_zip(path):
        gtfs_path = os.path.join(os.getcwd(), 'tmp')
        if not os.path.exists(gtfs_path):
            os.makedirs(gtfs_path)
        import zipfile
        with zipfile.ZipFile(path, 'r') as zip_ref:
            zip_ref.extractall(gtfs_path)
        gtfs_path = os.path.join(gtfs_path, os.path.splitext(os.path.basename(path))[0])
    else:
        gtfs_path = path

    services = read_services_from_calendar(gtfs_path, day=day)
    stop_times, stop_times_db, stops_db, trips_db, routes_db = read_gtfs_to_db_like_tables(gtfs_path)
    schedule = parse_db_to_schedule_dict(stop_times_db, stops_db, trips_db, routes_db, services)

    if persistence.is_zip(path):
        shutil.rmtree(os.path.dirname(gtfs_path))

    return schedule, stops_db
示例#2
0
def test_is_zip_identifies_folder_isnt_zip():
    assert not persistence.is_zip(os.path.join('path', 'to', 'dir'))
示例#3
0
def test_is_zip_identifies_zip():
    assert persistence.is_zip(os.path.join('path', 'to', 'dir', 'file.zip'))