Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e25f72eff | |||
| c4de3d61bb | |||
| 391e4c1267 | |||
| 84568c355f | |||
| 8264db80e9 | |||
| 6ecabb9ffa |
Binary file not shown.
2080
Oiseaux_europe.csv
2080
Oiseaux_europe.csv
File diff suppressed because it is too large
Load Diff
36
README.md
Normal file
36
README.md
Normal 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
BIN
Transparent300px.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 100 B |
118
bashbirds.sh
118
bashbirds.sh
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
VERSION="v0.9"
|
||||
VERSION="v1.1"
|
||||
|
||||
red="\033[1;31m"
|
||||
greenbold="\033[1;32m"
|
||||
@@ -8,6 +8,7 @@ green="\033[0;32m"
|
||||
yellow="\033[0;33m"
|
||||
yellowbold="\033[1;33m"
|
||||
bold="\033[1m"
|
||||
italic="\033[3m"
|
||||
#bold_under="\033[1;4m"
|
||||
underline="\033[4m"
|
||||
reset="\033[0m"
|
||||
@@ -15,13 +16,13 @@ reset="\033[0m"
|
||||
dotenv () {
|
||||
set -a
|
||||
# shellcheck disable=SC1091
|
||||
[ -f ".env" ] && . ".env" || echo -e "${red}\nNo .env file found ! No token for gotify.${reset}"
|
||||
[ -f ".env" ] && . ".env" || echo -e "${red}\nNo .env file found ! Could'nt get update from Github.'.${reset}"
|
||||
set +a
|
||||
}
|
||||
|
||||
dotenv
|
||||
|
||||
### ChangeNotes: .
|
||||
### ChangeNotes: Minor corrections.
|
||||
Github="https://github.com/bruno21/bashbirds"
|
||||
# Repo normal:
|
||||
#RawUrl="https://raw.githubusercontent.com/Bruno21/bashbirds/main/bashbirds.sh"
|
||||
@@ -36,10 +37,24 @@ ScriptWorkDir="$(dirname "$ScriptPath")" # /Users/bruno/Documents/Scripts/bashbi
|
||||
### 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
|
||||
#[[ $LatestRelease != $VERSION ]] && new="($LatestRelease)" || new=""
|
||||
|
||||
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() {
|
||||
option=$1
|
||||
|
||||
@@ -55,8 +70,10 @@ req2() {
|
||||
|
||||
#read -p "Pause: " choice
|
||||
|
||||
query2="SELECT * FROM liste;"
|
||||
result2=$(sqlite3 ./birds.db "$query2")
|
||||
|
||||
#query2="SELECT * FROM liste;"
|
||||
query2="SELECT Francais, Autres, Latin, Anglais, Ordre, Famille, Liens FROM liste;"
|
||||
result2=$(sqlite3 "$ScriptWorkDir/birds.db" "$query2")
|
||||
#echo "$result2"
|
||||
|
||||
i=1
|
||||
@@ -71,19 +88,37 @@ req2() {
|
||||
or="${array[4]}"
|
||||
fa="${array[5]}"
|
||||
ln="${array[6]}"
|
||||
|
||||
|
||||
#echo "$ln"
|
||||
#read -r -p "Would you like to update? y/[n]: " SelfUpdate
|
||||
|
||||
[[ $aut != "" ]] && z="($aut)" || z=""
|
||||
|
||||
if [ $ext = ".md" ]; then
|
||||
echo "| $fr $z |" >>"$f"
|
||||
echo "|--------------------------------------------------|" >>"$f"
|
||||
echo "| $lat |" >> "$f"
|
||||
echo "| $en |" >> "$f"
|
||||
echo "| $or |" >> "$f"
|
||||
echo "| $fa |" >> "$f"
|
||||
echo "| $ln |" >> "$f"
|
||||
echo "" >> "$f"
|
||||
|
||||
#echo "| $fr $z |" >>"$f"
|
||||
#echo "|--------------------------------------------------|" >>"$f"
|
||||
#echo "| $lat |" >> "$f"
|
||||
#echo "| $en |" >> "$f"
|
||||
#echo "| $or |" >> "$f"
|
||||
#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 /> | [$fr]($ln)<br /> |"'\n'
|
||||
birds+="| Liens (oiseaux.net)<br /> | [$fr]($ln)<br /> |"'\n'
|
||||
birds+='\n'
|
||||
|
||||
elif [ $ext = ".html" ]; then
|
||||
firstletter="${fr:0:1}"
|
||||
|
||||
firstletter="${fr:0:1}"
|
||||
|
||||
if [ $firstletter != $old_index ]; then
|
||||
index+=("$firstletter")
|
||||
@@ -116,12 +151,20 @@ req2() {
|
||||
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
|
||||
}
|
||||
|
||||
html() {
|
||||
|
||||
echo -e "${yellow}Exporting html file ${italic}$ScriptWorkDir/liste_oiseaux.html !${reset}"
|
||||
|
||||
cat > liste_oiseaux.html << EOF
|
||||
<!DOCTYPE html>
|
||||
@@ -222,8 +265,10 @@ req1() {
|
||||
if [[ "${request,,}" == "all" ]]; then
|
||||
request="";
|
||||
fi
|
||||
query1="SELECT * FROM liste WHERE Francais LIKE \"%$request%\" OR Autres LIKE \"%$request%\" OR Latin LIKE \"%$request%\"";
|
||||
result1=$(sqlite3 ./birds.db "$query1")
|
||||
|
||||
request=$(echo "$request" | sed 'y/áàâäçéèêëîïìôöóùúüñÂÀÄÇÉÈÊËÎÏÔÖÙÜÑ/aaaaceeeeiiiooouuunAAACEEEEIIOOUUN/')
|
||||
|
||||
query1="SELECT * FROM liste WHERE Fra LIKE \"%$request%\" OR Aut LIKE \"%$request%\" OR Latin LIKE \"%$request%\"";
|
||||
result1=$(sqlite3 "$ScriptWorkDir/birds.db" "$query1")
|
||||
|
||||
if [ -n "$result1" ]; then
|
||||
@@ -232,12 +277,12 @@ req1() {
|
||||
cmpt=1
|
||||
while IFS='|' read -ra array2;
|
||||
do
|
||||
aut2="${array2[1]}"
|
||||
lat2="${array2[2]}"
|
||||
en2="${array2[3]}"
|
||||
or2="${array2[4]}"
|
||||
fa2="${array2[5]}"
|
||||
lnk2="${array2[6]}"
|
||||
fr2="${array2[0]}"
|
||||
aut2="${array2[2]}"
|
||||
lat2="${array2[4]}"
|
||||
en2="${array2[5]}"
|
||||
or2="${array2[6]}"
|
||||
fa2="${array2[7]}"
|
||||
lnk2="${array2[8]}"
|
||||
|
||||
tag2="$fr2"
|
||||
@@ -326,24 +371,21 @@ if [[ "$VERSION" != "$LatestRelease" ]] ; then
|
||||
[[ "$SelfUpdate" =~ [yY] ]] && self_update
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -f ./birds.db ]; then
|
||||
|
||||
### Database is present or not ?
|
||||
if [ ! -f "$ScriptWorkDir/birds.db" ]; then
|
||||
echo -e "${red}No database found !${reset}"
|
||||
fi
|
||||
exit 1
|
||||
### 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."
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
while getopts "b:hmw" options; do
|
||||
|
||||
22
insert.sh
22
insert.sh
@@ -13,8 +13,8 @@ reset="\033[0m"
|
||||
dir=$(dirname "$0") # /Users/bruno/Documents/Scripts/keywords2insta
|
||||
|
||||
if [ ! -f ./birds.db ]; then
|
||||
cmd0="CREATE TABLE liste (Francais string, Autres string, Latin string, Anglais string, Ordre string, Famille string, Liens string);"
|
||||
echo "$cmd0" | sqlite3 ./birds_plus.db
|
||||
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.db
|
||||
|
||||
if [ $? -ne 0 ]; then exit 0; fi
|
||||
fi
|
||||
@@ -34,20 +34,24 @@ if [ -f "$dir"/Oiseaux_europe.csv ]; then
|
||||
((skip_headers--))
|
||||
else
|
||||
fr="${array[0]}"
|
||||
aut="${array[1]}"
|
||||
lat="${array[2]}"
|
||||
en="${array[3]}"
|
||||
or="${array[4]}"
|
||||
fa="${array[5]}"
|
||||
ln="${array[6]}"
|
||||
fr_wa="${array[1]}"
|
||||
aut="${array[2]}"
|
||||
aut_wa="${array[3]}"
|
||||
lat="${array[4]}"
|
||||
en="${array[5]}"
|
||||
or="${array[6]}"
|
||||
fa="${array[7]}"
|
||||
ln="${array[8]}"
|
||||
|
||||
fr=$(echo "$fr" | sed "s/'/''/g")
|
||||
fr_wa=$(echo "$fr_wa" | sed "s/'/''/g")
|
||||
aut=$(echo "$aut" | sed "s/'/''/g")
|
||||
aut_wa=$(echo "$aut_wa" | sed "s/'/''/g")
|
||||
en=$(echo "$en" | sed "s/'/''/g")
|
||||
or=$(echo "$or" | 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
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user