Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial feeds for Pennsylvania #518

Merged
merged 2 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions feeds/us-pa.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"maintainers": [
{
"name": "Marcus Lundblad",
"github": "mlundblad"
}
],
"sources": [
{
"name": "SEPTA-Rail",
"type": "transitland-atlas",
"transitland-atlas-id": "f-dr4-septa~rail"
},
{
"name": "SEPTA-Rail",
"type": "transitland-atlas",
"transitland-atlas-id": "f-septa~rail~rt"
},
{
"name": "SEPTA-Bus",
"type": "transitland-atlas",
"transitland-atlas-id": "f-dr4-septa~bus"
},
{
"name": "SEPTA-Bus",
"type": "transitland-atlas",
"transitland-atlas-id": "f-septa~rt"
}
]
}
14 changes: 12 additions & 2 deletions src/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pathlib import Path
from datetime import datetime, timezone
from utils import eprint
from zipfile import ZipFile

import email.utils
import requests
Expand All @@ -17,6 +18,7 @@
import subprocess
import shutil
import region_helpers
import io


def validate_source_name(name: str):
Expand Down Expand Up @@ -121,8 +123,16 @@ def fetch_source(self, dest_path: Path, source: Source) -> bool:
last_modified_server = email.utils.parsedate_to_datetime(
server_headers["last-modified"])

with open(dest_path, "wb") as dest:
dest.write(response.content)
if "#" in download_url:
# if URL contains #, treat the path after # as an embedded ZIP file
sub_path = download_url.partition("#")[2]
zipfile = ZipFile(io.BytesIO(response.content))

with open(dest_path, "wb") as dest:
dest.write(zipfile.read(sub_path))
else:
with open(dest_path, "wb") as dest:
dest.write(response.content)

# Set server mtime on local file
if last_modified_server:
Expand Down