word: mkimg-google tool to download images
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 23 May 2020 03:06:00 +0000 (05:06 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 6 Jun 2020 01:49:20 +0000 (03:49 +0200)
Automatic population with top results searching each term:

perl -E 'sub flat {map { ref ? flat(@$_) : $_ } @_}
say for flat do "./wordlist.inc.pl"'

Good for testing; definitely requires further moderation to release:
avoiding false friends (e.g. mug commonly isn't a midge), finding better
representations, and at least nicely cropping to aspect ratio.

tools/mkimg-google [new file with mode: 0755]

diff --git a/tools/mkimg-google b/tools/mkimg-google
new file mode 100755 (executable)
index 0000000..1e1f7a8
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+CURL='curl -sSf'
+QUERYURL="https://www.google.com/search?tbm=isch&pws=0&hl=nl&num=1&q="
+ARGMATCH='<img [^>]+src="(http[^"]+)"'
+
+for q in "$@"
+do
+       [ -e "$q.jpg" ] && continue
+       echo "$q"
+       QUERYARG="%22$q%22"
+       QUERYRES=$($CURL "$QUERYURL$QUERYARG" | perl -nE "say for /$ARGMATCH/" | head -1)
+       $CURL "$QUERYRES" -o "$q.jpg" || continue
+done