first upload

This commit is contained in:
FrederikBaerentsen 2020-06-23 15:02:27 +02:00
parent f16ba24f24
commit a464e9014a

68
lego_dl.sh Normal file
View File

@ -0,0 +1,68 @@
#!/bin/bash
echo "----> Starting Download of all LEGO instructions from https://brickset.com/exportscripts/instructions"
firstline=0
logfile="lego_errors.log"
#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 "$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 $filename
if [ -f "$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