Skip to content

Commit

Permalink
gtfs-importer: use curl instead of wget to download GTFS
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst authored and hbruch committed Oct 4, 2023
1 parent ffc11e8 commit 5f0039b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
9 changes: 5 additions & 4 deletions gtfs-importer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT

# curl is needed to download the GTFS
# moreutils is needed for sponge
# postgresql-client is needed for psql
RUN apt update && apt install -y \
bash \
curl \
moreutils \
postgresql-client \
unzip \
wget \
zstd \
&& rm -rf /var/lib/apt/lists/*

RUN \
wget -nv \
-U 'gtfs-importer (github.com/mobidata-bw/ipl-orchestration)' \
-O /usr/local/bin/gtfstidy \
curl -fsSL \
-H 'User-Agent: gtfs-importer (github.com/mobidata-bw/ipl-orchestration)' \
-o /usr/local/bin/gtfstidy \
"https://github.com/patrickbr/gtfstidy/releases/download/v0.2/gtfstidy.v0.2.$TARGETOS.$TARGETARCH" \
&& chmod +x /usr/local/bin/gtfstidy

Expand Down
17 changes: 15 additions & 2 deletions gtfs-importer/import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,22 @@ tidied_path="$gtfs_tmp_dir/tidied.gtfs"
print_bold "Downloading & extracting the GTFS feed from $GTFS_DOWNLOAD_URL."
set -x

# Using wget's -c & -N is not an option here, see https://gist.github.com/derhuerst/745cf09fe5f3ea2569948dd215bbfe1a
# Using wget with both -c *and* -N is not an option here, so we use curl.
# see also https://gist.github.com/derhuerst/745cf09fe5f3ea2569948dd215bbfe1a
# Note: This *does not* work with an incomplete local download!
# todo: use a (more?) correct & efficient mirroring script
wget -nv -U "$ua" -O "$zip_path" "$gtfs_url"
# wget -nv -U "$ua" -O "$zip_path" "$gtfs_url"
# flags logic modified from https://superuser.com/q/1710172
curl_flags=()
if test -e "$zip_path"; then
curl_flags+=(-z "$zip_path")
fi
curl -fsSL \
-H "User-Agent: $ua" \
--compressed -R \
-o "$zip_path" \
"${curl_flags[@]}" \
"$gtfs_url"
rm -rf "$extracted_path"
unzip -d "$extracted_path" "$zip_path"

Expand Down

0 comments on commit 5f0039b

Please sign in to comment.