Export html
-option -w
This commit is contained in:
169
bashbirds.sh
169
bashbirds.sh
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
VERSION="v0.7"
|
||||
VERSION="v0.9"
|
||||
|
||||
red="\033[1;31m"
|
||||
greenbold="\033[1;32m"
|
||||
@@ -41,16 +41,26 @@ echo -e "${yellowbold}Bashbird${reset} $VERSION\n"
|
||||
|
||||
|
||||
req2() {
|
||||
f_md="liste_oiseaux.md"
|
||||
if [ -f "./$f_md" ]; then
|
||||
rm "./$f_md"
|
||||
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
|
||||
|
||||
#read -p "Pause: " choice
|
||||
|
||||
query2="SELECT * FROM liste;"
|
||||
result2=$(sqlite3 ./birds.db "$query2")
|
||||
#echo "$result2"
|
||||
|
||||
i=1
|
||||
index=()
|
||||
array=()
|
||||
while IFS='|' read -ra array;
|
||||
do
|
||||
@@ -63,20 +73,147 @@ req2() {
|
||||
ln="${array[6]}"
|
||||
[[ $aut != "" ]] && z="($aut)" || z=""
|
||||
|
||||
echo "| $fr $z |" >>"$f_md"
|
||||
echo "|--------------------------------------------------|" >>"$f_md"
|
||||
echo "| $lat |" >> "$f_md"
|
||||
echo "| $en |" >> "$f_md"
|
||||
echo "| $or |" >> "$f_md"
|
||||
echo "| $fa |" >> "$f_md"
|
||||
echo "| $ln |" >> "$f_md"
|
||||
echo "" >> "$f_md"
|
||||
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"
|
||||
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"
|
||||
|
||||
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
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
html() {
|
||||
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() {
|
||||
echo -e "${bold}Recherche: <$1>${reset}"
|
||||
|
||||
@@ -85,7 +222,6 @@ req1() {
|
||||
request="";
|
||||
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%\"";
|
||||
result1=$(sqlite3 ./birds.db "$query1")
|
||||
|
||||
@@ -209,11 +345,10 @@ Help() {
|
||||
echo "-w Export html."
|
||||
}
|
||||
|
||||
while getopts "b:hm" options; do
|
||||
while getopts "b:hmw" options; do
|
||||
case "${options}" in
|
||||
# b) Bird="${OPTARG}" ;;
|
||||
b) req1 "${OPTARG}" ;;
|
||||
m) req2 ;;
|
||||
m|w) req2 "${options}" ;;
|
||||
v) printf "%s\n" "$VERSION" ; exit 0 ;;
|
||||
h|*) Help ; exit 2 ;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user