kanji koohii FORUM
tool to automatically generate pics from vocab list? - Printable Version

+- kanji koohii FORUM (http://forum.koohii.com)
+-- Forum: Learning Japanese (http://forum.koohii.com/forum-4.html)
+--- Forum: Learning resources (http://forum.koohii.com/forum-9.html)
+--- Thread: tool to automatically generate pics from vocab list? (/thread-12249.html)



tool to automatically generate pics from vocab list? - kraemder - 2014-10-05

I love having pictures in my SRS deck but it can take hours making them. Is there possibly a tool out there that will take a list of vocab and generate a list of images (and save them to my computer) from google/bing for me? Obviously they wouldn't be as good as if I picked them out myself but it really takes a long time. BTW I don't use ANKI (I use Flashcards Deluxe) but I would think any tools made for anki would also work..


tool to automatically generate pics from vocab list? - lauri_ranta - 2014-10-12

Here's a retarded shell script that uses the Google Images API:

cat ~/wordlist.txt|while read l;do curl "$(curl -sG --data-urlencode "q=$l" 'https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=large&imgsz=large|xlarge'|grep -o '"unescapedUrl":"[^"]*'|cut -d\" -f4|grep -Ei '\.(jpg|jpeg)$'|head -n1)" -o "$l.jpg";done

You can run the script on OS X or Linux by pasting it to a terminal application after putting one word per line to ~/wordlist.txt.

Example images for 10 random words from Core 6000:

[Image: 20141012160538.png]


tool to automatically generate pics from vocab list? - kraemder - 2014-10-12

I don't suppose that script will work with Windows 7 at all? That seems pretty nice.


tool to automatically generate pics from vocab list? - vix86 - 2014-10-12

Get Cygwin.

It'll handle Unix based shell commands like cat/grep/curl and BASH scripts.

EDIT: Make sure you run the script inside the Cygwin shell and not the normal Windows command shell.


tool to automatically generate pics from vocab list? - balloonguy - 2014-10-13

Here's a powershell translation of the script that will work out of the box on Windows 7:

Add-Type -AssemblyName System.Web
cat words.txt |%{$q=$_; (new-object system.net.webclient).DownloadString('https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=large&imgsz=large|xlarge&q=' + [System.Web.HttpUtility]::UrlEncode($q)) |%{$_ -match '"unescapedUrl":"([^"]*?\.(jpg|jpeg))"'; (new-object system.net.webclient).DownloadFile($Matches[1], "$pwd\$q.jpg")}}

and here's a slightly cleaner version if you have powershell 3 or above installed (default on Windows 8):

Add-Type -AssemblyName System.Web
cat words.txt| %{$q=$_;Invoke-RestMethod (Invoke-RestMethod ('https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=large&imgsz=large|xlarge&q=' + [System.Web.HttpUtility]::UrlEncode($q)) | select -ExpandProperty responseData | select -ExpandProperty results | ? {$_.unescapedUrl -match "\.(jpg|jpeg)$"} | select -first 1 -ExpandProperty unescapedUrl) -OutFile ($q + ".jpg")}


tool to automatically generate pics from vocab list? - jmignot - 2014-10-14

lauri_ranta Wrote:Here's a retarded shell script that uses the Google Images API:

cat ~/wordlist.txt|while read l;do curl "$(curl -sG --data-urlencode "q=$l" 'https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=large&imgsz=large|xlarge'|grep -o '"unescapedUrl":"[^"]*'|cut -d\" -f4|grep -Ei '\.(jpg|jpeg)$'|head -n1)" -o "$l.jpg";done

You can run the script on OS X or Linux by pasting it to a terminal application after putting one word per line to ~/wordlist.txt.
Just for completeness: this script should be run in the (default on Mac) "bash" shell. It fails in, e.g, tcsh


tool to automatically generate pics from vocab list? - kraemder - 2014-10-14

I did the windows 7 script given and it actually worked. I was surprised. I was expecting to have to get help or something since I have no familiarity with this powershell or anything.

I noticed that when I used the korean list of vocab I got a couple of errors (no result found maybe?) but with the english counterpart that was never a problem. And if I use the target language (actually I did a korean list of vocab) it will occasionally put an image with that exact word in it as the result. So I think it's more desirable to use the English translation list instead. And I got no errors that time when I did it.

And it works! Wow! It works! Pretty cool. I would think this post could be useful for other people making flashcard decks too. Thanks.


tool to automatically generate pics from vocab list? - kraemder - 2014-10-14

Seems like it poops out if the vocabulary list is too long at about 170 words or so. Still really useful for decks I make but if I download a big premade deck lacking images then hmm would have to just break it up I guess.

*edit*

I updated my powershell and tried the slightly cleaner script. It got to 210 words and then died. It literally just hung. The other script was just using the same image for every word after 170 or something and seemed like it would have done so until it finished all the words.


tool to automatically generate pics from vocab list? - vix86 - 2014-10-15

Just a wild guess, but the script may be dying because google is throttling the requests.


tool to automatically generate pics from vocab list? - kraemder - 2014-10-15

I was thinking so too. Although the script doesn't seem to be going all that fast but that makes the most sense. Any way to add a delay in the script?


tool to automatically generate pics from vocab list? - balloonguy - 2014-10-15

You can try adding sleep -s 5; after the first curly brace, but seeing as google only allows 100 searches a day for free when you use the official api, you'll still probably get cut off. If you really want to, you could register for an azure marketplace account and use the bing api. You get 5000 searches a month free.


tool to automatically generate pics from vocab list? - gaiaslastlaugh - 2014-10-15

I'm thinking of trying to write a Web utility that will do this on a large frequency list. If anyone knows of a better image search API (i.e., one that doesn't charge $5 per 1,000 queries), let me know. I found http://pixplorer.co.uk/, but it returns very limited (and tiny) results.

FWIW, it looks like Bing Search allows 5,000 free queries/mo. Instagram places no daily limits, but limits you to 5,000 queries/hour.


tool to automatically generate pics from vocab list? - kraemder - 2014-10-16

I got 889 words before it hanged by adding the 5 second delay.


tool to automatically generate pics from vocab list? - balloonguy - 2014-10-16

Flickr allows 3600 per hour. I'm surprised there isn't a set of freely licensed stock images.