34 lines
766 B
Text
34 lines
766 B
Text
|
#!/usr/bin/env bash
|
||
|
|
||
|
set -euo pipefail
|
||
|
|
||
|
if [ "$#" -ne 1 ]; then
|
||
|
echo "Usage: prepare-fantoir-db path-to-fantoir-db"
|
||
|
echo ""
|
||
|
echo "ERROR: Missing fantoir db"
|
||
|
exit 1
|
||
|
fi
|
||
|
fantoirDb="$1"
|
||
|
|
||
|
# Setup tmp working dir
|
||
|
tmpDir=$(mktemp -d)
|
||
|
posteData="${tmpDir}"/poste.csv
|
||
|
tmpSql="${tmpDir}"/import-insee-codes.sql
|
||
|
clean_tmp () {
|
||
|
rm -r "${tmpDir}"
|
||
|
}
|
||
|
trap clean_tmp EXIT
|
||
|
|
||
|
echo "Downloading the latest laposte insee data"
|
||
|
echo ""
|
||
|
curl "https://datanova.laposte.fr/explore/dataset/laposte_hexasmal/download/?format=csv&timezone=Europe/Berlin&lang=fr&use_labels_for_header=true&csv_separator=%3B" > "${posteData}"
|
||
|
|
||
|
cat >"${tmpSql}" <<EOF
|
||
|
.separator ";"
|
||
|
.import ${posteData} poste_insee
|
||
|
EOF
|
||
|
|
||
|
echo "Importing data to DB"
|
||
|
echo ""
|
||
|
sqlite3 "${fantoirDb}" < "${tmpSql}"
|