axione-elig-test/scripts/import-laposte-insee.sh
Félix Baylac-Jacqué 3acd1dd349 Adapt backend to new fantoir data schema
We updated the fantoir DB schema. See
https://git.alternativebit.fr/NinjaTrappeur/fast-fantoir/src/branch/master
for more informations.
2022-02-12 16:30:07 +01:00

30 lines
635 B
Bash
Executable file

#!/usr/bin/env bash
set -eau -o pipefail
if [ "$#" -ne 2 ]; then
echo "Usage: import-laposte-insee.sh path-to-laposte-insee-CSV fantoir-sqlite-db-path"
echo ""
echo "ERROR: Missing laposte CSV."
echo "You can download it at https://www.data.gouv.fr/fr/datasets/base-officielle-des-codes-postaux/"
exit 1
fi
tmpDir=$(mktemp -d)
clean_tmp () {
rm -r "${tmpDir}"
}
trap clean_tmp EXIT
tmpSql="${tmpDir}"/import-laposte-hexasmal.sql
echo "Importing laposte/insee hexasmal data into the fantoir db."
cat >"${tmpSql}" <<EOF
.separator ";"
.import $1 insee
EOF
sqlite3 "${2}" < "${tmpSql}"
echo "Data imported"