DataHoarder_scripts/lego_dl.sh

71 lines
2.1 KiB
Bash
Raw Normal View History

2020-06-23 15:02:27 +02:00
#!/bin/bash
echo "----> Starting Download of all LEGO instructions from https://brickset.com/exportscripts/instructions"
firstline=0
logfile="lego_errors.log"
2020-06-23 15:09:56 +02:00
downloadFolder="Instructions"
2020-06-23 15:02:27 +02:00
#error_level:
# 0 no errors reported
# 1 Download errors reported
# 2 Existing files and download errors reported
2020-06-23 15:19:59 +02:00
error_level=1
2020-06-23 15:02:27 +02:00
echo "" > $logfile
if [ -f "instructions" ]; then
echo "---> Using existing instructions file. Manually delete it to redownload..."
else
echo -ne "---> Downloading csv from Brickset..."
wget https://brickset.com/exportscripts/instructions &> /dev/null
if [[ "$?" != 0 ]]; then
echo "Error... Exiting!"
exit;
else
echo "Done!"
fi
fi
while IFS=, read -r ID LINK NAME DESC ADDED RETRIVED
do
if [ "$firstline" = 0 ]; then
firstline=1
else
#echo "I got:$ID - $LINK - $NAME - $DESC - $ADDED - $RETRIVED"
tID=$(sed -e 's/^"//' -e 's/"$//' <<<"$ID")
tLINK=$(sed -e 's/^"//' -e 's/"$//' <<<"$LINK")
tNAME=$(sed -e 's/^"//' -e 's/"$//' <<<"$NAME")
tADDED=$(sed -e 's/^"//' -e 's/"$//' <<<"$ADDED")
tDESC=$(sed -e 's/^"//' -e 's/"$//' <<<"$DESC")
filename=$tID"_"${tNAME// /_}"_("${tDESC// /_}")_"$tADDED".pdf"
2020-06-23 15:09:56 +02:00
if [ -f "$downloadFolder/$filename" ]; then
2020-06-23 15:02:27 +02:00
echo "-> $tID exists. Skipping..."
if [[ $error_level = 2 ]]; then
echo "$filename exists." >> $logfile
fi
else
if [[ "$tDESC" = "{No longer listed at LEGO.com}" ]] ; then
echo "-> $tID is not available. Skipping..."
if [[ $error_level = 1 || $error_level = 2 ]]; then
echo "$filename is not available." >> $logfile
fi
else
echo -ne "--> $tID downloading now..."
2020-06-23 15:28:15 +02:00
curl -H "Mozilla/5.0 (platform; rv:75.0) Gecko/20100101 Firefox/75.0" $tLINK --silent --output "Instructions/$filename"
2020-06-23 15:09:56 +02:00
if [ -f "$downloadFolder/$filename" ]; then
2020-06-23 15:02:27 +02:00
echo "Done!"
else
echo "ERROR!"
echo "--> Not downloaded. Try again manually..."
if [[ $error_level = 1 || $error_level = 2 ]]; then
echo "$filename was not downloaded. Check CURL" >> $logfile
fi
fi
2020-06-23 15:19:59 +02:00
#random sleep in order to not look like a script
sleep $(( ( RANDOM % 10 ) + 1 ))
2020-06-23 15:02:27 +02:00
fi
fi
fi
done < instructions