Skip to content

Instantly share code, notes, and snippets.

@simonjenny simonjenny/lego.sh
Last active Mar 13, 2019

Embed
What would you like to do?
Find Lego building instructions by set number from the command line and open the PDF in the default browser
#!/usr/bin/env bash
URL=$(curl --silent "https://www.lego.com//service/biservice/search?fromIndex=0&locale=en-US&onlyAlternatives=false&prefixText=${1}" | jq -r '.products[0].buildingInstructions[0].pdfLocation')
[[ -x $BROWSER ]] && exec "$BROWSER" "$URL"
path=$(which xdg-open || which gnome-open || which open) && exec "$path" "$URL"
echo "Error: Can't find default browser"
@simonjenny

This comment has been minimized.

Copy link
Owner Author

simonjenny commented Feb 21, 2019

Usage : ./lego.sh SETNUMBER
Example :
./lego.sh 70321

@simonjenny

This comment has been minimized.

Copy link
Owner Author

simonjenny commented Mar 13, 2019

Neue Version:

#!/usr/bin/env bash
ARRAY=()
var=1
rows=$(curl --silent "https://www.lego.com//service/biservice/search?fromIndex=0&locale=en-US&onlyAlternatives=false&prefixText=${1}"|jq -r '.products[0].buildingInstructions[].pdfLocation')
for row in $rows;
do
  ARRAY+=(${row})
  echo "$((var++)). ${row}"
done
echo -ne "Welche Anleitung soll ich öffnen Tim? "
read n
URL="${ARRAY[n-1]}"
[[ -x $BROWSER ]] && exec "$BROWSER" "$URL"
path=$(which xdg-open || which gnome-open || which open) && exec "$path" "$URL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.