Compare commits

14 Commits

Author SHA1 Message Date
11bad4f0cd test 2025-01-06 10:35:31 +01:00
ddb25adba3 v1.1.4 2025-01-06 09:48:12 +01:00
54532c7f23 test 2025-01-06 09:44:48 +01:00
9debf8e7f9 test 2025-01-06 09:41:58 +01:00
9166fe0e8b ChangeNotes
change to curl -s -r 0-1000
2025-01-06 09:28:09 +01:00
bdb26651b1 v 1.1.3
-won’t display changes notes
2025-01-06 09:23:46 +01:00
9e9a58ff9f v1.1.1
bugfix with .env path
2025-01-06 09:02:32 +01:00
1e25f72eff v 1.1
-corrige un bug lorsque le script était lancé depuis un lien symbolique
-affiche le nombre d’oiseaux dans la base
2025-01-06 08:36:46 +01:00
c4de3d61bb minor correction 2024-11-02 13:53:01 +01:00
391e4c1267 README.md 2024-11-02 13:46:44 +01:00
84568c355f Affichage du nom du fichier d’export (html ou md) 2024-10-18 09:48:09 +02:00
8264db80e9 Version 1.0
-ajout d’un nouveau champ dans la table pour faire des recherches sans accent (bashbird et insert)
-refonte de l’export markdown
2024-10-18 09:21:20 +02:00
6ecabb9ffa v 0.9.1 2024-10-14 09:25:55 +02:00
2c78917894 Export html
-option -w
2024-08-20 18:05:47 +02:00
7 changed files with 1342 additions and 1118 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

36
README.md Normal file
View File

@@ -0,0 +1,36 @@
# bashbird
Script that queries a SQLite database about a bird and returns various information (vernacular name, English name, family, order and links to [oiseaux.net](https://oiseaux.net)).
#### 1) bashbirds.sh
<u>Usage</u>:
./bashbird.sh -b etourneau
<u>Others files</u>:
- Oiseaux europe.xlsm: export from Oiseaux.net website
- Oiseaux europe.csv:same as format .csv
- insert.sh: script to create birds.db database from .csv export (Usage: ./insert.sh)
- birds.db: SQLite database
- liste_oiseaux.html: html export
- liste_oiseaux.md: markdown export
- Transparent300px.png: usefull for markdown export (table width)
<u>Options</u>:
- -b \< bird \>: a bird to search (-b etourneau)
- -b all: search for all birds
- -m: export markdown
- -w: export html
- -h: help
Notes:
- insert.sh deletes and recreates the database each time it is launched (no update)

BIN
Transparent300px.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 B

View File

@@ -1,6 +1,42 @@
#!/usr/bin/env bash #!/usr/bin/env bash
VERSION="v0.7" VERSION="v1.1.4"
### Variables for self updating
ScriptArgs=( "$@" )
ScriptPath="$(readlink -f "$0")" # /Users/bruno/Documents/Scripts/bashbirds/bashbirds.sh
ScriptWorkDir="$(dirname "$ScriptPath")" # /Users/bruno/Documents/Scripts/bashbirds
dotenv () {
set -a
# shellcheck disable=SC1091
[ -f "$ScriptWorkDir/.env" ] && . "$ScriptWorkDir/.env" || echo -e "${red}\nNo .env file found ! Could'nt get update from Github.'.${reset}"
set +a
}
dotenv
### ChangeNotes: 1.1.4 curl 2ko
### ChangeNotes: 1.1.3 Won't display Changes notes
### ChangeNotes: 1.1.1 Bugfix .env path
### ChangeNotes: 1.1 Bugfix when script was run with symlink
### ChangeNotes: 1.0 Minor corrections.
Github="https://github.com/bruno21/bashbirds"
# Public Repo:
#RawUrl="https://raw.githubusercontent.com/Bruno21/bashbirds/main/bashbirds.sh"
# Private Repo:
RawUrl="https://x-access-token:$GITHUB_TOKEN@raw.githubusercontent.com/Bruno21/bashbirds/main/bashbirds.sh"
### Check if there's a new release of the script:
LatestRelease="$(curl -s -r 0-50 $RawUrl | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
#LatestChanges="$(curl -s -r 0-2000 $RawUrl | sed -n "/ChangeNotes/s/# ChangeNotes: //p")"
LatestChanges="$(curl -s -r 0-2000 $RawUrl | grep "^### ChangeNotes:" | sed 's/### ChangeNotes://g')"
#[[ $LatestRelease != $VERSION ]] && new="($LatestRelease)" || new=""
#echo "$LatestRelease"
#echo "$LatestChanges"
red="\033[1;31m" red="\033[1;31m"
greenbold="\033[1;32m" greenbold="\033[1;32m"
@@ -8,49 +44,50 @@ green="\033[0;32m"
yellow="\033[0;33m" yellow="\033[0;33m"
yellowbold="\033[1;33m" yellowbold="\033[1;33m"
bold="\033[1m" bold="\033[1m"
italic="\033[3m"
#bold_under="\033[1;4m" #bold_under="\033[1;4m"
underline="\033[4m" underline="\033[4m"
reset="\033[0m" reset="\033[0m"
dotenv () {
set -a
# shellcheck disable=SC1091
[ -f ".env" ] && . ".env" || echo -e "${red}\nNo .env file found ! No token for gotify.${reset}"
set +a
}
dotenv
### ChangeNotes: .
Github="https://github.com/bruno21/bashbirds"
# Repo normal:
#RawUrl="https://raw.githubusercontent.com/Bruno21/bashbirds/main/bashbirds.sh"
# Repo privé:
RawUrl="https://x-access-token:$GITHUB_TOKEN@raw.githubusercontent.com/Bruno21/bashbirds/main/bashbirds.sh"
### Variables for self updating
ScriptArgs=( "$@" )
ScriptPath="$(readlink -f "$0")" # /Users/bruno/Documents/Scripts/bashbirds/bashbirds.sh
ScriptWorkDir="$(dirname "$ScriptPath")" # /Users/bruno/Documents/Scripts/bashbirds
### Check if there's a new release of the script:
LatestRelease="$(curl -s -r 0-50 $RawUrl | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
LatestChanges="$(curl -s -r 0-200 $RawUrl | sed -n "/ChangeNotes/s/### ChangeNotes: //p")"
echo $LatestRelease
echo -e "${yellowbold}Bashbird${reset} $VERSION\n" echo -e "${yellowbold}Bashbird${reset} $VERSION\n"
req2() { ### Help Function:
f_md="liste_oiseaux.md" Help() {
if [ -f "./$f_md" ]; then echo "Syntax: birds.sh [OPTION]"
rm "./$f_md" echo "Example: birds.sh -b buse"
fi echo
read -p "Pause: " choice echo "Options:"
echo "-b -b <bird>, -b all."
echo "-h Print this Help."
echo "-m Export markdown."
echo "-v Prints current version."
echo "-w Export html."
}
query2="SELECT * FROM liste;" req2() {
result2=$(sqlite3 ./birds.db "$query2") option=$1
case $option in
m) ext=".md" ;;
w) ext=".html";old_index="_" ;;
esac
f="liste_oiseaux$ext"
if [ -f "./$f" ]; then
rm "./$f"
fi
#read -p "Pause: " choice
query2="SELECT Francais, Autres, Latin, Anglais, Ordre, Famille, Liens FROM liste;"
result2=$(sqlite3 "$ScriptWorkDir/birds.db" "$query2")
#echo "$result2" #echo "$result2"
i=1
index=()
array=() array=()
while IFS='|' read -ra array; while IFS='|' read -ra array;
do do
@@ -61,22 +98,172 @@ req2() {
or="${array[4]}" or="${array[4]}"
fa="${array[5]}" fa="${array[5]}"
ln="${array[6]}" ln="${array[6]}"
[[ $aut != "" ]] && z="($aut)" || z="" [[ $aut != "" ]] && z="($aut)" || z=""
echo "| $fr $z |" >>"$f_md" if [ $ext = ".md" ]; then
echo "|--------------------------------------------------|" >>"$f_md"
echo "| $lat |" >> "$f_md" #echo "| $fr $z |" >>"$f"
echo "| $en |" >> "$f_md" #echo "|--------------------------------------------------|" >>"$f"
echo "| $or |" >> "$f_md" #echo "| $lat |" >> "$f"
echo "| $fa |" >> "$f_md" #echo "| $en |" >> "$f"
echo "| $ln |" >> "$f_md" #echo "| $or |" >> "$f"
echo "" >> "$f_md" #echo "| $fa |" >> "$f"
#echo "| $ln |" >> "$f"
#echo "" >> "$f"
birds+="| $fr | $z |"'\n'
birds+="|------------------------ | --------------------------|"'\n'
birds+="| Vernaculaire | $lat |"'\n'
birds+="| Anglais | $en |"'\n'
birds+="| Ordre | $or |"'\n'
birds+="| Famille | $fa |"'\n'
#birds+="| Liens (oiseaux.net)<br />![](/Users/bruno/Pictures/Transparent300px.png) | [$fr]($ln)<br />![](/Users/bruno/Pictures/Transparent300px.png) |"'\n'
birds+="| Liens (oiseaux.net)<br />![](Transparent300px.png) | [$fr]($ln)<br />![](Transparent300px.png) |"'\n'
birds+='\n'
elif [ $ext = ".html" ]; then
firstletter="${fr:0:1}"
if [ $firstletter != $old_index ]; then
index+=("$firstletter")
#bird+="<tr class='bird'><td class='bold'><a href='#$firstletter'></a>$fr</td><td>$aut</td><td>$lat</td><td>$en</td></tr>"
bird+="<tr class='bird'><td class='bold'><a id='$firstletter'></a>$fr</td><td>$aut</td><td>$lat</td><td>$en</td></tr>"
else
bird+="<tr class='bird'><td class='bold'>$fr</td><td>$aut</td><td>$lat</td><td>$en</td></tr>"
fi
bird+="<tr class='family'><td>$or</td><td>$fa</td><td></td><td><a href='$ln'>Oiseaux.net</a></tr>"
if [ $firstletter != $old_index ]; then
bird+="<tr class='family textcenter'><td colspan='4'>PLACEHOLDER</td></tr>"
else
bird+="<tr class='family'><td colspan='4'></td></tr>"
fi
old_index="$firstletter"
fi
done <<< "$result2" done <<< "$result2"
if [ $ext = ".html" ]; then
newArr=(); while IFS= read -r -d '' x; do newArr+=("$x"); done < <(printf "%s\0" "${index[@]}" | sort -uz)
for val in ${!newArr[@]}
do
liens_index+="<a href='#${newArr[$val]}'>${newArr[$val]}</a> | "
done
liens_index="${liens_index:0:-3}"
z=${bird//PLACEHOLDER/$liens_index}
bird="$z"
html
elif [ $ext = ".md" ]; then
echo -e "${yellow}Exporting markdown file ${italic}$ScriptWorkDir/liste_oiseaux$ext !${reset}"
bird=$(echo "$birds" | sed 's/\
//g')
echo -e "$bird" > "liste_oiseaux$ext"
fi
exit 0 exit 0
} }
html() {
echo -e "${yellow}Exporting html file ${italic}$ScriptWorkDir/liste_oiseaux.html !${reset}"
cat > liste_oiseaux.html << EOF
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<title>Liste oiseaux d'Europe...</title>
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: Helvetica, Calibri, Arial, sans-serif;
background: #e0e5b6;
#font-weight: 300;
#font-size: 15px;
#color: #333;
}
table {
width: 100%;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
padding: 10px;
}
caption {
letter-spacing: 3px;
font-weight: 600;
font-size: 28px;
padding: 16px;
}
h2 {
letter-spacing: 3px;
}
a {
color: #898121;
}
a:hover {
color: #914f1e;
}
.bird {
background-color: #ccd5ae;
}
.link {
background-color: #e0e5b6;
}
.family {
background-color: #faedce;
}
.bold {
font-weight: bold;
}
.textcenter {
text-align: center;
}
.index {
width: 550px;
margin: auto;
}
.td75 {
width: 75%;
background-color: #bbb;
}
.td25 {
width: 25%;
}
</style>
<link rel="stylesheet" href="">
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<link rel="shortcut icon" href="">
</head>
<body>
<br /><br />
<table id="anchor-cask">
<caption>Liste des oiseaux d'Europe.</caption>
<div class='index'>$liens_index</div>
$bird
</table>
</body>
</html>
EOF
}
req1() { req1() {
echo -e "${bold}Recherche: <$1>${reset}" echo -e "${bold}Recherche: <$1>${reset}"
@@ -85,9 +272,10 @@ req1() {
if [[ "${request,,}" == "all" ]]; then if [[ "${request,,}" == "all" ]]; then
request=""; request="";
fi fi
#query1="SELECT * FROM liste WHERE Francais LIKE \"%$1%\" OR Autres LIKE \"%$1%\" OR Latin LIKE \"%$1%\"";
query1="SELECT * FROM liste WHERE Francais LIKE \"%$request%\" OR Autres LIKE \"%$request%\" OR Latin LIKE \"%$request%\""; request=$(echo "$request" | sed 'y/áàâäçéèêëîïìôöóùúüñÂÀÄÇÉÈÊËÎÏÔÖÙÜÑ/aaaaceeeeiiiooouuunAAACEEEEIIOOUUN/')
result1=$(sqlite3 ./birds.db "$query1")
query1="SELECT * FROM liste WHERE Fra LIKE \"%$request%\" OR Aut LIKE \"%$request%\" OR Latin LIKE \"%$request%\"";
result1=$(sqlite3 "$ScriptWorkDir/birds.db" "$query1") result1=$(sqlite3 "$ScriptWorkDir/birds.db" "$query1")
if [ -n "$result1" ]; then if [ -n "$result1" ]; then
@@ -96,12 +284,12 @@ req1() {
cmpt=1 cmpt=1
while IFS='|' read -ra array2; while IFS='|' read -ra array2;
do do
aut2="${array2[1]}" fr2="${array2[0]}"
lat2="${array2[2]}" aut2="${array2[2]}"
en2="${array2[3]}" lat2="${array2[4]}"
or2="${array2[4]}" en2="${array2[5]}"
fa2="${array2[5]}" or2="${array2[6]}"
lnk2="${array2[6]}" fa2="${array2[7]}"
lnk2="${array2[8]}" lnk2="${array2[8]}"
tag2="$fr2" tag2="$fr2"
@@ -154,7 +342,7 @@ self_update_curl() {
cp "$ScriptPath" "$ScriptPath".bak cp "$ScriptPath" "$ScriptPath".bak
if [[ $(builtin type -P curl) ]]; then if [[ $(builtin type -P curl) ]]; then
curl -L $RawUrl > "$ScriptPath" ; chmod +x "$ScriptPath" curl -L $RawUrl > "$ScriptPath" ; chmod +x "$ScriptPath"
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments printf "\n%s\n" "--- starting over with the updated version ---"
exec "$ScriptPath" "${ScriptArgs[@]}" >/dev/null # run the new script with old arguments exec "$ScriptPath" "${ScriptArgs[@]}" >/dev/null # run the new script with old arguments
exit 1 # exit the old instance exit 1 # exit the old instance
elif [[ $(builtin type -P wget) ]]; then elif [[ $(builtin type -P wget) ]]; then
@@ -183,37 +371,33 @@ self_update() {
} }
### Version check & initiate self update ### Version check & initiate self update
printf "New version available! %b%s%b ⇒ %b%s%b \n Change Notes: %s \n" "$c_yellow" "$VERSION" "$c_reset" "$c_green" "$LatestRelease" "$c_reset" "$LatestChanges" if [[ "$VERSION" != "$LatestRelease" ]] ; then
printf "New version available! %b%s%b ⇒ %b%s%b \nChange Notes:\n%s \n" "$c_yellow" "$VERSION" "$c_reset" "$c_green" "$LatestRelease" "$c_reset" "$LatestChanges" printf "New version available! %b%s%b ⇒ %b%s%b \nChange Notes:\n%s \n" "$c_yellow" "$VERSION" "$c_reset" "$c_green" "$LatestRelease" "$c_reset" "$LatestChanges"
if [[ -z "$AutoUp" ]] ; then if [[ -z "$AutoUp" ]] ; then
read -r -p "Would you like to update? y/[n]: " SelfUpdate read -r -p "Would you like to update? y/[n]: " SelfUpdate
[[ "$SelfUpdate" =~ [yY] ]] && self_update [[ "$SelfUpdate" =~ [yY] ]] && self_update
fi fi
fi fi
if [ ! -f ./birds.db ]; then ### Database is present or not ?
if [ ! -f "$ScriptWorkDir/birds.db" ]; then if [ ! -f "$ScriptWorkDir/birds.db" ]; then
echo -e "${red}No database found !${reset}" echo -e "${red}No database found !${reset}"
exit 1
else
query="SELECT COUNT(Francais) FROM liste";
result5=$(sqlite3 "$ScriptWorkDir/birds.db" "$query")
if [ -n "$result5" ]; then
echo -e "\n${bold}A birds database that return keywords for Lightroom.${reset}"
echo -e "$result5 birds founds in database...\n"
Help
fi fi
fi fi
### Help Function:
Help() {
echo "Syntax: birds.sh [OPTION]"
echo "Example: birds.sh -b buse"
echo
echo "Options:"
echo "-b -b <bird>, -b all."
echo "-h Print this Help."
echo "-m Export markdown."
echo "-v Prints current version."
echo "-w Export html."
}
while getopts "b:hm" options; do
while getopts "b:hmw" options; do while getopts "b:hmw" options; do
# b) Bird="${OPTARG}" ;;
case "${options}" in case "${options}" in
m) req2 ;; b) req1 "${OPTARG}" ;;
m|w) req2 "${options}" ;; m|w) req2 "${options}" ;;
v) printf "%s\n" "$VERSION" ; exit 0 ;; v) printf "%s\n" "$VERSION" ; exit 0 ;;
h|*) Help ; exit 2 ;; h|*) Help ; exit 2 ;;

BIN
birds.db

Binary file not shown.

View File

@@ -13,8 +13,8 @@ reset="\033[0m"
dir=$(dirname "$0") # /Users/bruno/Documents/Scripts/keywords2insta dir=$(dirname "$0") # /Users/bruno/Documents/Scripts/keywords2insta
if [ ! -f ./birds.db ]; then if [ ! -f ./birds.db ]; then
cmd0="CREATE TABLE liste (Francais string, Autres string, Latin string, Anglais string, Ordre string, Famille string, Liens string);" cmd0="CREATE TABLE liste (Francais string, Fra string, Autres string, Aut string, Latin string, Anglais string, Ordre string, Famille string, Liens string);"
echo "$cmd0" | sqlite3 ./birds_plus.db echo "$cmd0" | sqlite3 ./birds.db
if [ $? -ne 0 ]; then exit 0; fi if [ $? -ne 0 ]; then exit 0; fi
fi fi
@@ -34,20 +34,24 @@ if [ -f "$dir"/Oiseaux_europe.csv ]; then
((skip_headers--)) ((skip_headers--))
else else
fr="${array[0]}" fr="${array[0]}"
aut="${array[1]}" fr_wa="${array[1]}"
lat="${array[2]}" aut="${array[2]}"
en="${array[3]}" aut_wa="${array[3]}"
or="${array[4]}" lat="${array[4]}"
fa="${array[5]}" en="${array[5]}"
ln="${array[6]}" or="${array[6]}"
fa="${array[7]}"
ln="${array[8]}"
fr=$(echo "$fr" | sed "s/'/''/g") fr=$(echo "$fr" | sed "s/'/''/g")
fr_wa=$(echo "$fr_wa" | sed "s/'/''/g")
aut=$(echo "$aut" | sed "s/'/''/g") aut=$(echo "$aut" | sed "s/'/''/g")
aut_wa=$(echo "$aut_wa" | sed "s/'/''/g")
en=$(echo "$en" | sed "s/'/''/g") en=$(echo "$en" | sed "s/'/''/g")
or=$(echo "$or" | sed "s/'/''/g") or=$(echo "$or" | sed "s/'/''/g")
fa=$(echo "$fa" | sed "s/'/''/g") fa=$(echo "$fa" | sed "s/'/''/g")
cmd1="INSERT INTO liste (Francais, Autres, Latin, Anglais, Ordre, Famille, Liens) VALUES ('$fr','$aut','$lat','$en','$or','$fa','$ln');" cmd1="INSERT INTO liste (Francais, Fra, Autres, Aut, Latin, Anglais, Ordre, Famille, Liens) VALUES ('$fr','$fr_wa','$aut','$aut_wa','$lat','$en','$or','$fa','$ln');"
echo "$cmd1" | sqlite3 ./birds.db echo "$cmd1" | sqlite3 ./birds.db
fi fi