GooPoetry

Google’s got the soul of a poet, or at least knows how to toss a good word salad.

Perhaps you didn’t realize it, but with a little help from a hack, Google can churn out poetry that will bring a tear to your eye. Okay, perhaps not. But Google sure can mix a mean word salad.

This hack takes a query and uses random words from the titles returned by the query to spit out a poem of random length. The user can specify a poetry “flavor,” adding words to the array to be used. The flavors in this version of the hack include: hippie, beatnik, and Swedish Chef. Here’s a paean to the O’Reilly Camel Book, flavored by Shakespeare:

-- 3rd alas! to the
O'Reilly thee |
2nd Camel Book
Catalog: | hither Book Welcome oreilly.com Edition --
2000 Programming The
-- Dictionary] Book sirrah alas!
-- Perl 2000 2nd
2000 node: Camel Dictionary] Better node: Jargon oreilly.com
thee thee -- oreilly.com Programming 2nd oreilly.com

The Code

#!/usr/local/bin/perl # goopoetry.cgi # Generates a mean word salad. # goopoetry.cgi is called as a CGI with form input # Your Google API developer's key my $google_key='insert key here'; # Location of the GoogleSearch WSDL file my $google_wdsl = "./GoogleSearch.wsdl"; # Number of lines per poem my $numlines = 10; # Number of words per line my $numwords = 6; use strict; use SOAP::Lite; use CGI qw/:standard/; my $flavors = { 'Hippie' => ['wow', 'groovy man!', 'far out!', 'Right on!', 'funky', 'outta sight', 'Like,','peace out!', 'munchies'], 'Beatnik' ...

Get Google Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.