feat(bin): add bin/dload-zhv.sh
This commit is contained in:
parent
651b3c46c2
commit
388bc375c1
|
@ -0,0 +1,66 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
echo "Started..."
|
||||
#Started...
|
||||
#
|
||||
# special variable $# is the number of arguments
|
||||
if [ $# -lt 3 ] ; then
|
||||
echo 'Call ./<script> <work dir> <ZHV CSV output file> <GTFS CSV output file>'
|
||||
exit 1
|
||||
fi
|
||||
#
|
||||
WORK_DIR="$1"
|
||||
echo "WORK_DIR: $WORK_DIR"
|
||||
dloadDir=${WORK_DIR}/zhv
|
||||
echo "dloadDir: $dloadDir"
|
||||
rm -r $dloadDir
|
||||
mkdir -p $dloadDir
|
||||
logFile=${dloadDir}/wget-log.txt
|
||||
echo "logFile: $logFile"
|
||||
dloadFile=${dloadDir}/zhv.zip
|
||||
echo "dloadFile: $dloadFile"
|
||||
wget -o $logFile -O $dloadFile 'https://www.opendata-oepnv.de/index.php?id=1384&tx_vrrkit_view%5Bsharing%5D=eyJkYXRhc2V0IjoiZGV1dHNjaGxhbmR3ZWl0ZS1oYWx0ZXN0ZWxsZW5kYXRlbiIsInVzZXJJZCI6MTYxNH0%3D&tx_vrrkit_view%5Baction%5D=download&tx_vrrkit_view%5Bcontroller%5D=View'
|
||||
#
|
||||
unzipDir=${dloadDir}/unzip
|
||||
echo "unzipDir: $unzipDir"
|
||||
mkdir -p $unzipDir
|
||||
unzip -qq -d $unzipDir $dloadFile
|
||||
#
|
||||
csvFilePath=$(find $unzipDir -name '*.csv' -type f)
|
||||
echo "csvFilePath: $csvFilePath"
|
||||
#
|
||||
csvFile=$(basename $csvFilePath)
|
||||
echo "csvFile: $csvFile"
|
||||
csvFileNoExt="${csvFile%.*}"
|
||||
echo "csvFileNoExt: $csvFileNoExt"
|
||||
csvFileDot=${csvFileNoExt}-dot.csv
|
||||
echo "csvFileDot: $csvFileDot"
|
||||
csvFileDotPath=${unzipDir}/$csvFileDot
|
||||
echo "csvFileDotPath: $csvFileDotPath"
|
||||
sed 's/\([[:digit:]]\)\,\([[:digit:]]\)/\1.\2/g' $csvFilePath > $csvFileDotPath
|
||||
rm $csvFilePath
|
||||
#
|
||||
csvFileLower=${csvFileNoExt}-dot-lower.csv
|
||||
echo "csvFileLower: $csvFileLower"
|
||||
csvFileLowerPath=${unzipDir}/$csvFileLower
|
||||
echo "csvFileLowerPath: $csvFileLowerPath"
|
||||
sed '1s/\(.*\)/\L\1/' $csvFileDotPath > $csvFileLowerPath
|
||||
rm $csvFileDotPath
|
||||
#
|
||||
csvFileComma=${csvFileNoExt}-dot-lower-comma.csv
|
||||
echo "csvFileComma: $csvFileComma"
|
||||
csvFileCommaPath=${unzipDir}/$csvFileComma
|
||||
echo "csvFileCommaPath: $csvFileCommaPath"
|
||||
sed -E 's/(");(")/\1\,\2/g' $csvFileLowerPath > $csvFileCommaPath
|
||||
rm $csvFileLowerPath
|
||||
#
|
||||
ZHV_CSV_OUTPUT="$2"
|
||||
echo "ZHV_CSV_OUTPUT: $ZHV_CSV_OUTPUT"
|
||||
mv $csvFileCommaPath $ZHV_CSV_OUTPUT
|
||||
#
|
||||
GTFS_CSV_OUTPUT="$3"
|
||||
echo "GTFS_CSV_OUTPUT: $GTFS_CSV_OUTPUT"
|
||||
cp $ZHV_CSV_OUTPUT $GTFS_CSV_OUTPUT
|
||||
#
|
||||
echo "Done."
|
||||
#done.
|
Loading…
Reference in New Issue