1
0
Fork 0
extract_discord_research/extract.sh

84 lines
2.0 KiB
Bash
Raw Permalink Normal View History

2020-10-31 20:45:11 +00:00
#!/bin/bash
#***************************#
# extract.sh #
# #
# author : rick@gnous.eu #
# licence: GPL3 or later #
# #
#***************************#
2020-11-02 15:24:44 +00:00
fichierExtract="/tmp/file-tmp"
fichierB="$fichierExtract.b"
2021-03-31 00:39:30 +00:00
fichierJson="$fichierExtract.json"
2020-10-31 20:45:11 +00:00
################################################################################
# Télécharge le fichier .b se trouvant à lurl en paramètre et le dézip dans
# /tmp/file-tmp.
# Globals:
2020-11-02 15:24:44 +00:00
# $fichierB: le chemin vers le fichier compressé .b
# $fichierExtract: le chemin vers le fichier décompressé
2020-10-31 20:45:11 +00:00
# Arguments:
# $1: le curl (sans de --output) à faire pour récupérer le fichier
################################################################################
function recupDezip {
2020-11-02 15:24:44 +00:00
command="$@ --output $fichierB"
eval $command 2> /dev/null
if [ -f $fichierExtract ]
2020-10-31 20:45:11 +00:00
then
2020-11-02 15:24:44 +00:00
rm $fichierExtract
2020-10-31 20:45:11 +00:00
fi
2020-11-02 15:24:44 +00:00
brotli -d -S .b $fichierB
if [ $? -eq 1 ]
then
sleep 3s
recupDezip $@
fi
2020-10-31 20:45:11 +00:00
}
2021-03-31 00:39:30 +00:00
function recupJson {
command="$@ --output $fichierExtract"
eval $command 2> /dev/null
}
2020-10-31 20:45:11 +00:00
read -p "Entrez commande curl sans --compressed : " commandCurl
2021-03-31 00:39:30 +00:00
#recupDezip $commandCurl
recupJson $commandCurl
2020-10-31 20:45:11 +00:00
# on récupère le nombre de résultat pour avoir le nombre de page
nbResult=$(python3 help.py -g)
nbPage=$((nbResult / 25))
url=$(echo $commandCurl | cut -d\ -f2)
args=$(echo $commandCurl | cut -d\ -f3-)
url="${url::-1}&offset=${url: -1}"
if [ $((nbResult % 25)) -gt 0 ]
then
nbPage=$((nbPage + 1))
fi
2020-11-02 15:24:44 +00:00
echo
2020-10-31 20:45:11 +00:00
read -p "Attention ! $nbPage pages seront traités !"
if [ -f result.json ]
then
rm result.json
fi
2021-03-31 00:39:30 +00:00
#cp $fichierExtract result.json
2020-11-02 15:24:44 +00:00
cp $fichierExtract result.json
2020-10-31 20:45:11 +00:00
j=25
for i in $(seq 1 $nbPage)
do
newUrl="${url::-1}$j${url: -1}"
newCommand="curl $newUrl $args"
2021-03-31 00:39:30 +00:00
#recupDezip $newCommand
recupJson $newCommand
2020-10-31 20:45:11 +00:00
python3 help.py -u
j=$((j + 25))
2020-11-02 15:24:44 +00:00
echo -e "\r$i/$nbPage pages\c"
2020-10-31 20:45:11 +00:00
done