4 Commits
v1.0 ... 1.1

Author SHA1 Message Date
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
2 changed files with 67 additions and 20 deletions

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)

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
VERSION="v1.0" VERSION="v1.1"
red="\033[1;31m" red="\033[1;31m"
greenbold="\033[1;32m" greenbold="\033[1;32m"
@@ -8,6 +8,7 @@ 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"
@@ -41,6 +42,19 @@ LatestChanges="$(curl -s -r 0-200 $RawUrl | sed -n "/ChangeNotes/s/### ChangeNot
echo -e "${yellowbold}Bashbird${reset} $VERSION\n" echo -e "${yellowbold}Bashbird${reset} $VERSION\n"
### 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."
}
req2() { req2() {
option=$1 option=$1
@@ -59,7 +73,7 @@ req2() {
#query2="SELECT * FROM liste;" #query2="SELECT * FROM liste;"
query2="SELECT Francais, Autres, Latin, Anglais, Ordre, Famille, Liens FROM liste;" query2="SELECT Francais, Autres, Latin, Anglais, Ordre, Famille, Liens FROM liste;"
result2=$(sqlite3 ./birds.db "$query2") result2=$(sqlite3 "$ScriptWorkDir/birds.db" "$query2")
#echo "$result2" #echo "$result2"
i=1 i=1
@@ -139,7 +153,7 @@ req2() {
html html
elif [ $ext = ".md" ]; then elif [ $ext = ".md" ]; then
echo -e "${yellow}Exporting markdown file...${reset}" echo -e "${yellow}Exporting markdown file ${italic}$ScriptWorkDir/liste_oiseaux$ext !${reset}"
bird=$(echo "$birds" | sed 's/\ bird=$(echo "$birds" | sed 's/\
//g') //g')
echo -e "$bird" > "liste_oiseaux$ext" echo -e "$bird" > "liste_oiseaux$ext"
@@ -149,7 +163,7 @@ req2() {
} }
html() { html() {
echo -e "${yellow}Exporting html file ${italic}$ScriptWorkDir/liste_oiseaux.html !${reset}" echo -e "${yellow}Exporting html file ${italic}$ScriptWorkDir/liste_oiseaux.html !${reset}"
cat > liste_oiseaux.html << EOF cat > liste_oiseaux.html << EOF
@@ -254,7 +268,7 @@ req1() {
request=$(echo "$request" | sed 'y/áàâäçéèêëîïìôöóùúüñÂÀÄÇÉÈÊËÎÏÔÖÙÜÑ/aaaaceeeeiiiooouuunAAACEEEEIIOOUUN/') request=$(echo "$request" | sed 'y/áàâäçéèêëîïìôöóùúüñÂÀÄÇÉÈÊËÎÏÔÖÙÜÑ/aaaaceeeeiiiooouuunAAACEEEEIIOOUUN/')
query1="SELECT * FROM liste WHERE Fra LIKE \"%$request%\" OR Aut LIKE \"%$request%\" OR Latin LIKE \"%$request%\""; 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
@@ -357,24 +371,21 @@ if [[ "$VERSION" != "$LatestRelease" ]] ; then
[[ "$SelfUpdate" =~ [yY] ]] && self_update [[ "$SelfUpdate" =~ [yY] ]] && self_update
fi fi
fi fi
### 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
exit 1 exit 1
### Help Function: else
Help() { query="SELECT COUNT(Francais) FROM liste";
echo "Syntax: birds.sh [OPTION]" result5=$(sqlite3 "$ScriptWorkDir/birds.db" "$query")
echo "Example: birds.sh -b buse"
echo if [ -n "$result5" ]; then
echo "Options:" echo -e "\n${bold}A birds database that return keywords for Lightroom.${reset}"
echo "-b -b <bird>, -b all." echo -e "$result5 birds founds in database...\n"
echo "-h Print this Help." Help
echo "-m Export markdown." fi
echo "-v Prints current version."
echo "-w Export html."
fi fi
while getopts "b:hmw" options; do while getopts "b:hmw" options; do