Found this picture on the web today. Being a lazy programmer, I don't want to actually open google and type a couple of characters. Way too much work! This is such an important task that it should be automated.
Challenge
Everyone knows that the first image in a google search result is always the best. Hence it should be presented to the user.
You are to write a program or function which takes a string as parameter and displays the first image it finds on google when you search for that name + the words glamour shot
behind it.
Google search queries
To search for images on google, the url should contain the query parameter tbm=isch
and q=query
, with query
being the name you want to search for.
A valid query string for my name Bas
would be www.google.com/search?tbm=isch&q=Bas
Input
Your program or function takes a single parameter of input, which is the name you want to search for on google. This string will consist of the characters [a-z]
, [A-Z]
, [0-9]
and
(space). This string can be space seperated, to search for a space seperated string on google, one should replace the spaces with +
. For example, this is a valid query:
www.google.com/search?tbm=isch&q=Bassdrop+Cumberwubwubwub+glamour+shot
Output
The image can either be drawn to the screen, or saved to a file (in any format).
If the first search result on google is a gif file, you can either show the gif or show any frame of that gif.
Test cases
Run this snippet to see the expected results
<pre>f('Bas') // www.google.com/search?tbm=isch&q=Bas+glamour+shot
<img src="http://i.stack.imgur.com/IViaM.jpg" style="width:40%;height:40%"/>
<pre>f('Bassdrop Cumberwubwubwub') // www.google.com/search?tbm=isch&q=Bassdrop+Cumberwubwubwub+glamour+shot
<img src="http://i.stack.imgur.com/tdhvW.png" style="width:40%;height:40%"/>
This is code-golf, shortest code in bytes wins!
[a-z0-9]
, edited my post. The urls will look like the examples I provided, no encoding needed, just space to+
\$\endgroup\$A-Z
can also appear, judging by your example? \$\endgroup\$