69 lines
2.0 KiB
Bash
69 lines
2.0 KiB
Bash
#!/bin/bash
|
|
|
|
echo "----> Starting Download of all LEGO instructions from https://brickset.com/exportscripts/instructions"
|
|
firstline=0
|
|
logfile="lego_errors.log"
|
|
downloadFolder="Instructions"
|
|
#error_level:
|
|
# 0 no errors reported
|
|
# 1 Download errors reported
|
|
# 2 Existing files and download errors reported
|
|
|
|
error_level=2
|
|
|
|
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
|
|
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..."
|
|
curl $tLINK --silent --output "Instructions/$filename"
|
|
if [ -f "$downloadFolder/$filename" ]; then
|
|
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
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
done < instructions
|
|
|