From a464e9014a8b9269f741f82016a21aa1b5df7abe Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Tue, 23 Jun 2020 15:02:27 +0200 Subject: [PATCH] first upload --- lego_dl.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 lego_dl.sh diff --git a/lego_dl.sh b/lego_dl.sh new file mode 100644 index 0000000..41fec55 --- /dev/null +++ b/lego_dl.sh @@ -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 +