word: mkimg-google tool to download images
[sheet.git] / tools / mkimg-google
1 #!/bin/sh
2 CURL='curl -sSf'
3 QUERYURL="https://www.google.com/search?tbm=isch&pws=0&hl=nl&num=1&q="
4 ARGMATCH='<img [^>]+src="(http[^"]+)"'
5
6 for q in "$@"
7 do
8         [ -e "$q.jpg" ] && continue
9         echo "$q"
10         QUERYARG="%22$q%22"
11         QUERYRES=$($CURL "$QUERYURL$QUERYARG" | perl -nE "say for /$ARGMATCH/" | head -1)
12         $CURL "$QUERYRES" -o "$q.jpg" || continue
13 done