Last active
January 9, 2020 12:06
-
-
Save simonjenny/f19776ffb6a9afc266a79b502813a4bf to your computer and use it in GitHub Desktop.
Find Lego building instructions by set number from the command line and open the PDF in the default browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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? " | |
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
Usage : ./lego.sh SETNUMBER
Example :
./lego.sh 70321