« Auto-éditer un wikilivre/addappendix/reconstruction et tests du script addappendix » : différence entre les versions
m →script tests_addappendix.bash : WL:RD : * diverses retouches |
m →script addapendix.sh : WL:RD : * diverses retouches |
||
Ligne 15 : | Ligne 15 : | ||
#P ------------------------------- |
#P ------------------------------- |
||
VERSION= |
VERSION=220117 |
||
TEXTDOMAIN=addappendix |
TEXTDOMAIN=addappendix |
||
TEXTDOMAINDIR="/usr/share/locale" |
TEXTDOMAINDIR="/usr/share/locale" |
||
Ligne 28 : | Ligne 28 : | ||
#O Then print the short syntax ant exit -1 |
#O Then print the short syntax ant exit -1 |
||
then |
then |
||
echo -n -e "\033[31m" |
|||
echo $"No parameter. addappendix [ <full url of book> | ? | -v ]" |
echo -n $"No parameter. addappendix [ <full url of book> | ? | -v ]" |
||
⚫ | |||
echo -e "\033[0m" |
|||
⚫ | |||
⚫ | |||
fi |
|||
#O If firt parameter is '?' |
#O If firt parameter is '?' |
||
if [ "$1" = "?" ] |
if [ "$1" = "?" ] |
||
#O Then print syntax whih examples and exit 0 |
#O Then print syntax whih examples and exit 0 |
||
then |
then |
||
echo $"Syntax: addappendix [ <full url of book> | -v ]" |
echo -n -e "\033[32m" |
||
echo $"Syntax: addappendix [ <full url of book> | -v ]" |
|||
echo $"Example 1 : addappendix https://en.wikibooks.org/wiki/Wikibooks:Collections/Guide_to_Unix" |
echo $" Example 1 : addappendix https://en.wikibooks.org/wiki/Wikibooks:Collections/Guide_to_Unix" |
||
echo $"Example 2 : addappendix https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel" |
echo $" Example 2 : addappendix https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel" |
||
echo -e "\033[0m" |
|||
exit 0 |
exit 0 |
||
fi |
fi |
||
Ligne 44 : | Ligne 49 : | ||
#O Then print addapendix version |
#O Then print addapendix version |
||
then |
then |
||
echo |
echo -n -e "\033[32m" |
||
echo -n $"addapendix version : $VERSION" |
|||
echo -e "\033[0m" |
|||
exit 0 |
exit 0 |
||
fi |
fi |
||
#O *** First parameter analysis *** |
#O *** First parameter analysis *** |
||
⚫ | |||
#O Test if the first parameter points to wikibooks.org/wiki |
#O Test if the first parameter points to wikibooks.org/wiki |
||
if echo $1 | grep wikibooks.org/wiki |
if echo $1 | grep wikibooks.org/wiki |
||
then |
then |
||
echo |
echo -n -e "\033[32m" |
||
echo -n $" is a wiki-books" |
|||
echo -e "\033[0m" |
|||
else |
else |
||
echo |
echo -n -e "\033[31m" |
||
echo -n $"$1 is not a wiki-book on wikibooks.org" |
|||
echo -e "\033[0m" |
|||
exit -1 |
exit -1 |
||
fi |
fi |
||
#O Check if $1 file exist |
#O Check if $1 file exist |
||
if wget --spider $1 2>/dev/null; then |
if wget --spider $1 2>/dev/null; then |
||
echo -n -e "\033[32m" |
|||
⚫ | |||
⚫ | |||
echo -e "\033[0m" |
|||
else |
else |
||
echo -n -e "\033[31m" |
|||
⚫ | |||
echo -n $"File $1 is not found" |
|||
echo -e "\033[0m" |
|||
exit -1 |
exit -1 |
||
fi |
fi |
||
Ligne 67 : | Ligne 83 : | ||
#O Find the bookname |
#O Find the bookname |
||
echo $1 | awk -F"/" ' { print $NF }' > bookname.txt |
echo $1 | awk -F"/" ' { print $NF }' > bookname.txt |
||
read |
read Bookname<bookname.txt |
||
echo |
echo; echo -n -e "\033[1;32m" |
||
echo -n $"Book name : $Bookname" |
|||
⚫ | |||
echo -e "\033[0m" |
|||
⚫ | |||
echo $1 | awk -F"/" ' { print $5 }' > Compilations.txt |
|||
#O Télécharger la page compilée |
|||
read Compilations<Compilations.txt |
|||
⚫ | |||
echo -n -e "\033[1;32m" |
|||
wget -r -linif -k -p -E -i $1 |
|||
echo -n $"Compilations name: $Compilations" |
|||
echo -e "\033[0m" |
|||
if [ "$Compilations" = "Wikilivres:Compilations" ]; then Suffix=compiled; fi |
|||
if [ "$Compilations" = "Wikibokoks:Collections" ]; then Suffix=collection; fi |
|||
if test -z $Suffix; then Suffix=compiled; fi |
|||
echo -n -e "\033[1;32m" |
|||
echo "Suffix = $Suffix" |
|||
echo -e "\033[0m" |
|||
⚫ | |||
⚫ | |||
⚫ | |||
#O Create temp directory in Wordir |
|||
Workdir=~/Add_appendix |
|||
mkdir -p $Workdir/temp |
|||
##O Create the file bookname.suffix |
|||
#T *********************** |
|||
#O Create $Projectdir/resources/TMP to download |
|||
mkdir -p $Projectdir/resources/TMP |
|||
#O Download $1 |
|||
cd $Projectdir/resources/TMP |
|||
rm -Rf $Projectdir/resources/TMP/* 2> /dev/null |
|||
wget -N $1 -o $Workdir/temp/wget-log-télécharger.txt |
|||
ls -1 > ../filename.txt |
|||
read Filename<../filename.txt |
|||
if [ "$Filename" = "filename.txt" ]; then echo $"line 113: \$Filename = filename.txt error, exit -1"; exit -1; fi |
|||
rm ../filename.txt |
|||
#O go up in the directory resources and rename 'TMP' '$Filename' |
|||
cd .. |
|||
if test -e $Filename; then rm -R $Filename; fi |
|||
if test -d $Filename 2>/dev/null |
|||
then rm -R $Filename 2>/dev/null |
|||
fi |
|||
mv TMP $Filename |
|||
cd $Filename |
|||
#T ls -al |
|||
cat $Filename|grep "<li><a href=">extract-li |
|||
cat extract-li | sed "s/title=\"/\n[[/g" | grep -v "<li><a href=" |sed "s/\">/]]\n/g"|grep -v "</a>\|Cat\|<div" >extract-li1 |
|||
cat $Filename|grep "<dd><a href=">extract-dd |
|||
cat extract-dd | sed "s/title=\"/\n[[/g" | grep -v "<dd><a href=" |sed "s/\">/]]\n/g"|grep -v "</a>" >extract-dd1 |
|||
cat extract-dd1 > $Bookname.$Suffix |
|||
cat extract-li1 >> $Bookname.$Suffix |
|||
#T echo "$Bookname.$Suffix = " |
|||
cp $Bookname.$Suffix $Projectdir/$Bookname.$Suffix |
|||
#T *********************** |
|||
if test -e $Projectdir/$Bookname.$Suffix |
|||
then |
|||
echo -n -e "\033[1;32m" |
|||
echo -n "$Bookname.$Suffix : " |
|||
echo -e "\033[0m" |
|||
cat $Projectdir/$Bookname.$Suffix |
|||
⚫ | |||
#O Download the book in html form |
|||
#O Télécharger le site récursivement avec une profondeur infinie ( -linf ), \ |
|||
#O convertit les liens pour une consultation en local ( -k ), \ |
|||
#O rapatrie tous les fichiers nécessaires à l'affichage convenable d'une page HTML ( -p ) \ |
|||
#O et renomme toutes les pages HTML avec l'extension .html ( -E ) |
|||
echo; echo "Dowload $1" |
|||
wget -r -linf -k -p -E "$1" -o $Workdir/temp/wget-log-télécharger.txt |
|||
exit 0 |
exit 0 |
Version du 18 janvier 2022 à 12:09
- Cette page concerne le logiciel addappendix mis en paquet
script addapendix.sh
#!/bin/bash
#H Header doc
#H -------------------------------
#H File : tests/addappendix/addapendix.sh
#H Syntax : addapendix [ ? | -v ]
#H Created : 220113 by GC
#H Updated : 220113 by ... for
#O Organizational chart
#O -------------------------------
#P Programmers notes
#P -------------------------------
VERSION=220117
TEXTDOMAIN=addappendix
TEXTDOMAINDIR="/usr/share/locale"
export TEXTDOMAINDIR
#P . gettext for translation
. gettext.sh
#O Script begin here
#O If parameters is empty
if test -z $1
#O Then print the short syntax ant exit -1
then
echo -n -e "\033[31m"
echo -n $"No parameter. addappendix [ <full url of book> | ? | -v ]"
echo -e "\033[0m"
exit -1
fi
#O If firt parameter is '?'
if [ "$1" = "?" ]
#O Then print syntax whih examples and exit 0
then
echo -n -e "\033[32m"
echo $"Syntax: addappendix [ <full url of book> | -v ]"
echo $" Example 1 : addappendix https://en.wikibooks.org/wiki/Wikibooks:Collections/Guide_to_Unix"
echo $" Example 2 : addappendix https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel"
echo -e "\033[0m"
exit 0
fi
#O IF first parameter is "-v"
if [ "$1" = "-v" ]
#O Then print addapendix version
then
echo -n -e "\033[32m"
echo -n $"addapendix version : $VERSION"
echo -e "\033[0m"
exit 0
fi
#O *** First parameter analysis ***
#T echo "$1"
#O Test if the first parameter points to wikibooks.org/wiki
if echo $1 | grep wikibooks.org/wiki
then
echo -n -e "\033[32m"
echo -n $" is a wiki-books"
echo -e "\033[0m"
else
echo -n -e "\033[31m"
echo -n $"$1 is not a wiki-book on wikibooks.org"
echo -e "\033[0m"
exit -1
fi
#O Check if $1 file exist
if wget --spider $1 2>/dev/null; then
echo -n -e "\033[32m"
echo -n $"File $1 is found"
echo -e "\033[0m"
else
echo -n -e "\033[31m"
echo -n $"File $1 is not found"
echo -e "\033[0m"
exit -1
fi
#O Find the bookname
echo $1 | awk -F"/" ' { print $NF }' > bookname.txt
read Bookname<bookname.txt
echo; echo -n -e "\033[1;32m"
echo -n $"Book name : $Bookname"
echo -e "\033[0m"
echo $1 | awk -F"/" ' { print $5 }' > Compilations.txt
read Compilations<Compilations.txt
echo -n -e "\033[1;32m"
echo -n $"Compilations name: $Compilations"
echo -e "\033[0m"
if [ "$Compilations" = "Wikilivres:Compilations" ]; then Suffix=compiled; fi
if [ "$Compilations" = "Wikibokoks:Collections" ]; then Suffix=collection; fi
if test -z $Suffix; then Suffix=compiled; fi
echo -n -e "\033[1;32m"
echo "Suffix = $Suffix"
echo -e "\033[0m"
#O Create Bookname directory
install -d ~/Add_appendix/books/$Bookname
Projectdir=~/Add_appendix/books/$Bookname
#O Create temp directory in Wordir
Workdir=~/Add_appendix
mkdir -p $Workdir/temp
##O Create the file bookname.suffix
#T ***********************
#O Create $Projectdir/resources/TMP to download
mkdir -p $Projectdir/resources/TMP
#O Download $1
cd $Projectdir/resources/TMP
rm -Rf $Projectdir/resources/TMP/* 2> /dev/null
wget -N $1 -o $Workdir/temp/wget-log-télécharger.txt
ls -1 > ../filename.txt
read Filename<../filename.txt
if [ "$Filename" = "filename.txt" ]; then echo $"line 113: \$Filename = filename.txt error, exit -1"; exit -1; fi
rm ../filename.txt
#O go up in the directory resources and rename 'TMP' '$Filename'
cd ..
if test -e $Filename; then rm -R $Filename; fi
if test -d $Filename 2>/dev/null
then rm -R $Filename 2>/dev/null
fi
mv TMP $Filename
cd $Filename
#T ls -al
cat $Filename|grep "<li><a href=">extract-li
cat extract-li | sed "s/title=\"/\n[[/g" | grep -v "<li><a href=" |sed "s/\">/]]\n/g"|grep -v "</a>\|Cat\|<div" >extract-li1
cat $Filename|grep "<dd><a href=">extract-dd
cat extract-dd | sed "s/title=\"/\n[[/g" | grep -v "<dd><a href=" |sed "s/\">/]]\n/g"|grep -v "</a>" >extract-dd1
cat extract-dd1 > $Bookname.$Suffix
cat extract-li1 >> $Bookname.$Suffix
#T echo "$Bookname.$Suffix = "
cp $Bookname.$Suffix $Projectdir/$Bookname.$Suffix
#T ***********************
if test -e $Projectdir/$Bookname.$Suffix
then
echo -n -e "\033[1;32m"
echo -n "$Bookname.$Suffix : "
echo -e "\033[0m"
cat $Projectdir/$Bookname.$Suffix
fi
#O Download the book in html form
#O Télécharger le site récursivement avec une profondeur infinie ( -linf ), \
#O convertit les liens pour une consultation en local ( -k ), \
#O rapatrie tous les fichiers nécessaires à l'affichage convenable d'une page HTML ( -p ) \
#O et renomme toutes les pages HTML avec l'extension .html ( -E )
echo; echo "Dowload $1"
wget -r -linf -k -p -E "$1" -o $Workdir/temp/wget-log-télécharger.txt
exit 0
#O Script end
script tests_addappendix.bash
<syntaxhighlight lang="bash">
- !/bin/bash
- H Header doc
- H -------------------------------
- H File : tests/addappendix/tests_addapendix.bash
- H Syntax : ./tests_addapendix.bash
- H Created : 220113 by GC
- H Updated : 220113 by ... for
- O Organizational chart
- O -------------------------------
- P Programmers notes
- P -------------------------------
VERSION=220116
echo -e "\033[1;033mtest addappendix.sh with first param empty\033[0m" ./addappendix.sh sleep 3 echo "----"
echo -e "\033[1;033mtest addappendix.sh with first param = '?'\033[0m" ./addappendix.sh ? sleep 3 echo "----"
echo -e "\033[1;033mtest addappendix.sh with first param = '-v'\033[0m" ./addappendix.sh -v sleep 3 echo "----"
echo -e "\033[1;033mtest addappendix.sh with param = https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel\033[0m" ./addappendix.sh https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel
Résultat des tests
<syntaxhighligh> cardabela@jpl-W230SS:~/addappendix-211219/tests/addapendix$ ./tests_addapendix.bash test addappendix.sh with first param empty No parameter. addappendix [ <full url of book> | ? | -v ]
test addappendix.sh with first param = '?' Syntax: addappendix [ <full url of book> | -v ]
Example 1 : addappendix https://en.wikibooks.org/wiki/Wikibooks:Collections/Guide_to_Unix Example 2 : addappendix https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel
test addappendix.sh with first param = '-v' addapendix version : 220117
test addappendix.sh with param = https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel
is a wiki-books
File https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel is found
Book name : Faire_sa_fleur_de_sel Compilations name: Wikilivres:Compilations Suffix = compiled
Faire_sa_fleur_de_sel.compiled : Faire fleurir le sel/Couverture Faire fleurir le sel/Introduction Faire fleurir le sel/Préparation Faire fleurir le sel/Filtrer et aseptiser Faire fleurir le sel/Récolter
Dowload https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel
</syntaxhighligh>