30 lines
635 B
Bash
30 lines
635 B
Bash
|
#!/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"
|