1st commit

This commit is contained in:
2024-08-18 08:14:43 +02:00
commit 2513ae6eb9
4 changed files with 1181 additions and 0 deletions

54
insert.sh Executable file
View File

@@ -0,0 +1,54 @@
#!/usr/bin/env bash
red="\033[1;31m"
greenbold="\033[1;32m"
green="\033[0;32m"
yellow="\033[0;33m"
bold="\033[1m"
#bold_under="\033[1;4m"
underline="\033[4m"
reset="\033[0m"
dir=$(dirname "$0") # /Users/bruno/Documents/Scripts/keywords2insta
if [ ! -f ./apps.db ]; then
cmd0="CREATE TABLE liste (Francais string, Autres string, Latin string, Anglais string, Liens string);"
echo "$cmd0" | sqlite3 ./birds.db
fi
array=()
if [ -f "$dir"/Oiseaux_europe.csv ]; then
skip_headers=1
while IFS=';' read -ra array;
do
if ((skip_headers)); then # Ne pas lire le header
((skip_headers--))
else
fr="${array[0]}"
aut="${array[1]}"
lat="${array[2]}"
en="${array[3]}"
ln="${array[4]}"
fr=$(echo "$fr" | sed "s/'/''/g")
aut=$(echo "$aut" | sed "s/'/''/g")
en=$(echo "$en" | sed "s/'/''/g")
cmd1="INSERT INTO liste (Francais, Autres, Latin, Anglais, Liens) VALUES ('$fr','$aut','$lat','$en','$ln');"
echo "$cmd1" | sqlite3 ./birds.db
fi
done < <(grep "" "$dir"/Oiseaux_europe.csv) # lit la dernière ligne même si elle n'est pas vide
else
echo -e "${red}No .csv file found !${reset}"
exit 1
fi
query="SELECT * FROM liste;"
result=$(sqlite3 ./birds.db "$query")
#echo "$result"