feat(zhv): add zhv

This commit is contained in:
dancingCycle 2023-05-22 16:41:14 +02:00
parent fac1263226
commit 90d73bb104
7 changed files with 118 additions and 3 deletions

View File

@ -1,4 +1,4 @@
HOME=<set variable!>
# m h dom mon dow command
23 0 * * Tue,Thu cd $HOME/git/gtfs4delfi/dload && sh ./dload.sh <work dir> <url>
23 0 * * Tue,Thu cd $HOME/git/delfi/gtfs/dload && sh ./dload.sh <work dir> <url>
27 0 * * Tue,Thu echo 'Next!'

View File

@ -4,6 +4,5 @@
mkdir -p ~/git
cd ~/git
git clone https://git.wtf-eg.de/dancesWithCycles/delfi.git
cd delfi/
crontab -e
cd ~/git/delfi/
```

4
zhv/dload/crontab Normal file
View File

@ -0,0 +1,4 @@
HOME=<set variable!>
# m h dom mon dow command
23 0 * * Tue,Thu cd $HOME/git/delfi/zhv/dload && sh ./dload.sh <work dir> <url>
27 0 * * Tue,Thu echo 'Next!'

32
zhv/dload/dload.sh Normal file
View File

@ -0,0 +1,32 @@
#!/bin/bash
#
echo "Started..."
#Started...
#
# special variable $# is the number of arguments
if [ $# -lt 2 ] ; then
echo 'Call ./<script> <work dir> <dload URL>'
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"
dloadUrl=$2
echo "dloadUrl: $dloadUrl"
wget -o $logFile -O $dloadFile $dloadUrl
#
unzipDir=${dloadDir}/unzip
echo "unzipDir: $unzipDir"
mkdir -p $unzipDir
unzip -qq -d $unzipDir $dloadFile
#
echo "Done."
#done.

21
zhv/makefile Normal file
View File

@ -0,0 +1,21 @@
SHELL := /bin/bash
TABLES = stops
SCHEMA = zhv
psql = $(strip psql -v schema=$(SCHEMA))
# $(addprefix prefix,names…): The argument names is regarded as a series of names, separated by whitespace; prefix is used as a unit. The value of prefix is prepended to the front of each individual name and the resulting larger names are concatenated with single spaces between them.
#
# FORMAT(format_string [, format_arg [, ...] ])
load: $(addprefix load-,$(TABLES))
@$(psql) -t -A -c "SELECT FORMAT('* loaded %s', feed_file) WHERE feed_file = '$(GTFS)';"
copy: $(ZHV)
$(psql) -c "\copy zhv.stops(stop_seq_no,stop_type,stop_dhid,stop_parent,stop_name,stop_lat,stop_lon,stop_municipality_code,stop_municipality,stop_district_code,stop_district,stop_condition,stop_state,stop_description,stop_authority,stop_delfi_name,stop_tariff_dhid,stop_tariff_name) FROM '$<' DELIMITER ';' CSV HEADER;"
# -v: variable assignment, like the /set meta-command
# $<: name of the firest prerequisite
init: sql/schema.sql
$(psql) -v ON_ERROR_STOP=on -f $<

31
zhv/readme.md Normal file
View File

@ -0,0 +1,31 @@
# zhv
* checkout repository
```
mkdir ~/git && cd ~/git
git clone https://git.wtf-eg.de/dancesWithCycles/delfi.git
```
* configure cron
```
cd ~/git/delfi/zhv
cat dload/crontab
crontab -e
crontab -l
```
* make sure to set variables like `PGDATABASE`, `PGUSER`, `PGHOST`, `PGPORT` aaso. appropriately
* initialize database
```
cd ~/git/delfi/zhv
make init
```
* load database
```
cd ~/git/delfi/zhv
make copy ZHV=<CSV file>
```

28
zhv/sql/schema.sql Normal file
View File

@ -0,0 +1,28 @@
-- colon before variable: for a prepared statement using named placeholders, this will be a parameter name of the form :name
BEGIN;
CREATE SCHEMA IF NOT EXISTS :schema;
SET search_path to :schema, public;
CREATE TABLE stops(
stop_seq_no BIGSERIAL NOT NULL,
stop_type VARCHAR(7),
stop_dhid VARCHAR(63),
stop_parent VARCHAR(31),
stop_name TEXT,
stop_lat VARCHAR(31),
stop_lon VARCHAR(31),
stop_municipality_code VARCHAR(15),
stop_municipality VARCHAR(63),
stop_district_code VARCHAR(15),
stop_district VARCHAR(31),
stop_condition VARCHAR(31),
stop_state VARCHAR(31),
stop_description TEXT,
stop_authority TEXT,
stop_delfi_name VARCHAR(31),
stop_tariff_dhid VARCHAR(31),
stop_tariff_name TEXT,
CONSTRAINT stops_pkey PRIMARY KEY (stop_seq_no)
);
COMMIT;