Skip to content

Commit

Permalink
ci: Validate feed names
Browse files Browse the repository at this point in the history
  • Loading branch information
jbruechert committed Mar 3, 2024
1 parent 07ea2e5 commit 76f484e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
18 changes: 9 additions & 9 deletions feeds/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@
}
},
{
"name": "Sardegna-ASPO_Olbia",
"name": "Sardegna-ASPO-Olbia",
"type": "http",
"url": "https://www.aspo.it/wp-content/uploads/open_data.zip",
"license": {
"spdx-identifier": "CC-BY-4.0"
}
},
{
"name": "Sardegna-ATP_Nuoro",
"name": "Sardegna-ATP-Nuoro",
"type": "transitland-atlas",
"transitland-atlas-id": "f-s-atpnuoro"
},
{
"name": "Sardegna-ATP_Sassari",
"name": "Sardegna-ATP-Sassari",
"type": "transitland-atlas",
"transitland-atlas-id": "f-spnp-atpsassari"
},
Expand All @@ -56,23 +56,23 @@
"transitland-atlas-id": "f-snyr-ctmspa~cagliari"
},
{
"name": "Sardegna-Ferries-Collegamenti_marittimi_Corsica",
"name": "Sardegna-Ferries-Collegamenti-marittimi-Corsica",
"type": "http",
"url": "https://www.sardegnamobilita.it/opendata/R_SARDEGTRASP_00010_1_dati_mare_corsica.zip",
"license": {
"spdx-identifier": "CC-BY-4.0"
}
},
{
"name": "Sardegna-Ferries-Collegamenti_isole_minori",
"name": "Sardegna-Ferries-Collegamenti-isole-minori",
"type": "http",
"url": "https://www.sardegnamobilita.it/opendata/R_SARDEGTRASP_00006_1_dati_mare.zip",
"license": {
"spdx-identifier": "CC-BY-4.0"
}
},
{
"name": "Sardegna-Ferries-Sardinia_Ferries",
"name": "Sardegna-Ferries-Sardinia-Ferries",
"type": "http",
"url": "https://www.sardegnamobilita.it/opendata/R_SARDEGTRASP_00028_1_dati_sardinia_ferries.zip",
"license": {
Expand All @@ -88,23 +88,23 @@
}
},
{
"name": "Sardegna-Planes-Alghero_Airport",
"name": "Sardegna-Planes-Alghero-Airport",
"type": "http",
"url": "https://www.sardegnamobilita.it/opendata/R_SARDEGTRASP_00024_3_GTFS_timetable_winter_it.zip",
"license": {
"spdx-identifier": "CC-BY-4.0"
}
},
{
"name": "Sardegna-Planes-Cagliari_Airport",
"name": "Sardegna-Planes-Cagliari-Airport",
"type": "http",
"url": "https://www.sardegnamobilita.it/opendata/R_SARDEGTRASP_00030_10_cagliari_timetable.zip",
"license": {
"spdx-identifier": "CC-BY-4.0"
}
},
{
"name": "Sardegna-Planes-Olbia_Airport",
"name": "Sardegna-Planes-Olbia-Airport",
"type": "http",
"url": "https://www.sardegnamobilita.it/opendata/R_SARDEGTRASP_00025_10_olbia_timetable.zip",
"license": {
Expand Down
19 changes: 19 additions & 0 deletions src/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@
import shutil


def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)


def validate_source_name(name: str):
if " " in name:
eprint(f"Error: Feed names must not contain spaces, found {name}.")
sys.exit(1)

if "_" in name:
eprint(f"Error: Feed names must not contain underscores, found {name}.")
sys.exit(1)

if "/" in name:
eprint(f"Error: Feed names must not contain slashes, found {name}.")
sys.exit(1)


class Fetcher:
transitland_atlas: transitland.Atlas

Expand Down Expand Up @@ -142,6 +160,7 @@ def fetch(self, metadata: Path):
region_name = metadata_filename[:metadata_filename.rfind('.')]

for source in region.sources:
validate_source_name(source.name)
download_name = f"{region_name}_{source.name}"

print(f"Fetching {region_name}-{source.name}…")
Expand Down

0 comments on commit 76f484e

Please sign in to comment.