You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.1 KiB

4 years ago
#!/bin/bash
echo "----> Starting Download of all LEGO instructions from https://brickset.com/exportscripts/instructions"
firstline=0
logfile="lego_errors.log"
downloadFolder="Instructions"
4 years ago
#error_level:
# 0 no errors reported
# 1 Download errors reported
# 2 Existing files and download errors reported
4 years ago
error_level=1
4 years ago
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"
if [ -f "$downloadFolder/$filename" ]; then
4 years ago
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..."
4 years ago
curl -H "Mozilla/5.0 (platform; rv:75.0) Gecko/20100101 Firefox/75.0" $tLINK --silent --output "Instructions/$filename"
if [ -f "$downloadFolder/$filename" ]; then
4 years ago
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
4 years ago
#random sleep in order to not look like a script
sleep $(( ( RANDOM % 10 ) + 1 ))
4 years ago
fi
fi
fi
done < instructions