-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to generate license summary
- Loading branch information
1 parent
0d00eff
commit 7a78946
Showing
5 changed files
with
107 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env python3 | ||
# SPDX-FileCopyrightText: 2024 Jonah Brüchert <[email protected]> | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
import json | ||
import csv | ||
import io | ||
import transitland | ||
|
||
from pathlib import Path | ||
from metadata import * | ||
from zipfile import ZipFile | ||
|
||
|
||
if __name__ == "__main__": | ||
feed_dir = Path("feeds/") | ||
|
||
transitland_atlas = transitland.Atlas.load(Path("transitland-atlas/")) | ||
|
||
attributions = [] | ||
|
||
for feed in feed_dir.glob("*.json"): | ||
parsed = {} | ||
with open(feed, "r") as f: | ||
parsed = json.load(f) | ||
|
||
region = Region(parsed) | ||
for source in region.sources: | ||
if (type(source) == TransitlandSource): | ||
source = transitland_atlas.source_by_id(source) | ||
|
||
attribution = {} | ||
|
||
if source.license: | ||
if source.license.spdx_identifier: | ||
attribution["spdx_identifier"] \ | ||
= source.license.spdx_identifier | ||
if source.license.url: | ||
attribution["url"] = source.license.url | ||
|
||
attribution["copyright_holders"] = [] | ||
|
||
metadata_filename = feed.name | ||
region_name = metadata_filename[:metadata_filename.rfind('.')] | ||
|
||
feed_path = Path(f"out/{region_name}_{source.name}.gtfs.zip") | ||
|
||
attribution["filename"] = feed_path.name | ||
|
||
if not feed_path.exists(): | ||
print(f"Info: {feed_path} does not exist, skipping…") | ||
continue | ||
|
||
with ZipFile(feed_path) as z: | ||
with z.open("agency.txt", "r") as a: | ||
with io.TextIOWrapper(a) as at: | ||
agencyreader = \ | ||
csv.DictReader(at, delimiter=',', quotechar='"') | ||
for row in agencyreader: | ||
attribution["copyright_holders"] \ | ||
.append(row["agency_name"]) | ||
|
||
attributions.append(attribution) | ||
|
||
with open("out/license.json", "w") as outfile: | ||
json.dump(attributions, outfile, indent=4, ensure_ascii=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters