Google Hacks Free Open Book

Google Hacks

Previous Section Next Section

Hack 92 Finding Recipes

figs/expert.giffigs/hack92.gif

Let the Google API transform those random ingredients in your fridge into a wonderful dinner.

Google can help you find news, catalogs, discussions, web pages, and so much more—and it can also help you figure out what to have for dinner tonight!

This hack uses the Google API to help you transform those random ingredients in your fridge into a wonderful dinner. Well, you do have to do some of the work. But it all starts with this hack.

92.1 Using the Hack

This hack comes with a built-in form that calls the query and the recipe type, so there's no need to set up a separate form.

#!/usr/local/bin/perl
# goocook.cgi
# Finding recipes with google
# goocook.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";

use SOAP::Lite;
use CGI qw/:standard/;

my %recipe_types = (
  "General"           => "site:allrecipes.com | site:cooking.com | site:
epicurious.com | site:recipesource.com",
  "Vegetarian/Vegan"  => "site:fatfree.com | inurl:veganmania | inurl:
vegetarianrecipe | inurl:veggiefiles",
  "Wordwide Cuisine" => "site:Britannia.org | inurl:thegutsygourmet |  
inurl:simpleinternet | inurl:soupsong"
);

print
  header(  ),
  start_html("GooCook"),
  h1("GooCook"),
  start_form(-method=>'GET'),
  'Ingredients: ', textfield(-name=>'ingredients'),
  br(  ),
  'Recipe Type: ', popup_menu(-name=>'recipe_type', 
    -values=>[keys %recipe_types], -default=>'General'),
  br(  ),
  submit(-name=>'submit', -value=>"Get Cookin'!"),
  submit(-name=>'reset', -value=>"Start Over"),
  end_form(  ), p(  );

if (param('ingredients')) {
  my $google_search  = SOAP::Lite->service("file:$google_wdsl");
  my $results = $google_search -> 
    doGoogleSearch(
      $google_key, 
      param('ingredients') . " " . $recipe_types{param('recipe_type')}, 
      0, 10, "false", "",  "false", "", "latin1", "latin1"
    );
 
  @{$results->{'resultElements'}} or print "None";
  foreach (@{$results->{'resultElements'}}) {
    print p(
      b($_->{title}||'no title'), br(  ),
      a({href=>$_->{URL}}, $_->{URL}), br(  ),
      i($_->{snippet}||'no snippet')
    );
  }
}

print end_html(  );

92.2 Hacking the Hack

Of course the most obvious way to hack this hack is to add new recipe options to it. That involves first finding new recipe sites, and then adding them to the hack.

92.3 Finding New Recipe Domains

Adding new recipe sites entails finding the domains you want to search. Use the cooking section of Google's Directory to find recipes; start with recipe collections at http://directory.google.com/Top/Home/Cooking/Recipe_Collections/.

From here, find what you want and build it into a query supplement like the one in the form, surrounded by parens with each item separated by a |. Remember, using the site: syntax means you'll be searching for an entire domain. So if you find a great recipe site at http://www.geocities.com/reallygreat/food/recipes/, don't use the site: syntax to search it, use the inurl: search instead (inurl:geocities.com/reallygreat/food/recipes). Just remember that an addition like this counts heavily against your ten-word query limit.

Let's take an example. The Cookbook section of the Google directory has a Seafood section with several sites. Let's pull five examples out of that and make it a query supplement. Here's what one could look like:

(site:simplyseafood.com | site:baycooking.com | site:coastangler.com | site:
welovefish.com | site:sea-ex.com)

Next, test the query supplement in Google by adding a query term to it and running it as a search, for example:

salmon (site:simplyseafood.com | site:baycooking.com | site:coastangler.com 
| site:welovefish.com | site:sea-ex.com)

Run a few different queries with a few different query words (salmon, scallops, whatever) and make sure that you're getting a decent number of results. Once you're confident that you're getting a good selection of recipes, you'll need to add this new option to the hack. You'll need to add it to this part of the code:

my %recipe_types = (
  "General"           => "site:allrecipes.com | site:cooking.com | site:
epicurious.com | site:recipesource.com",
  "Vegetarian/Vegan"  => "site:fatfree.com | inurl:veganmania | inurl:
vegetarianrecipe | inurl:veggiefiles",
  "Wordwide Cuisine" => "site:Britannia.org | inurl:thegutsygourmet |  
inurl:simpleinternet | inurl:soupsong"
);

Simply add the name you want to call the option, =>, and the search string. Make sure you add it before closed parantheses and the semicolon.

my %recipe_types = (
  "General"           => "site:allrecipes.com | site:cooking.com | site:
epicurious.com | site:recipesource.com",
  "Vegetarian/Vegan"  => "site:fatfree.com | inurl:veganmania | inurl:
vegetarianrecipe | inurl:veggiefiles",
  "Wordwide Cuisine" => "site:Britannia.org | inurl:thegutsygourmet |  
inurl:simpleinternet | inurl:soupsong"
  
  "Seafood" =>  "site:simplyseafood.com | site:baycooking.com | site:
coastangler.com | site:welovefish.com | site:sea-ex.com"
  
);

You can add as many search sets as you want to the hack. You may want to add Chinese Cooking, Desserts, Soups, Salads, or any number of other options.

—Tara Calishain and Judy Hourihan

    Previous Section Next Section


         Main Menu
    Main Page
    Table of content
    Copyright
    Dedication
    Credits
    Foreword
    Preface
    Chapter 1. Searching Google
    Chapter 2. Google Special Services and Collections
    Chapter 3. Third-Party Google Services
    Chapter 4. Non-API Google Applications
    Chapter 5. Introducing the Google Web API
    Chapter 6. Google Web API Applications
    Chapter 7. Google Pranks and Games
    7.1 Hacks #86-92
    Hack 86 The No-Result Search (Prank)
    Hack 87 Google Whacking
    Hack 88 GooPoetry
    Hack 89 Creating Google Art
    Hack 90 Google Bounce
    Hack 91 Google Mirror
    Hack 92 Finding Recipes
    Chapter 8. The Webmaster Side of Google
    Colophon
    Index


    More Books
    PHP Hacks
    Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
    The Koran (Holy Qur'an)
    Macromedia Flash 8 Bible
    Search Engine Optimization for Dummies
    YouTube Traffic
    PHP 5 for Dummies
    Harry Potter and The Chamber of Secrets
    Harry Potter and the Sorcerer's Stone
    The Pilgrim's Progress
    Wireless Hacks
    Flash Hacks. 100 Industrial-Strength Tips & Tools
    PayPal Hacks. 100 Industrial-Strength Tips and Tools
    Amazon Hacks
    Pdf Hacks
    The Da Vinci Code
    Google Hacks
    The Holy Bible
    Windows XP For Dummies
    Harry Potter and the Half-Blood Prince
    Seo Book
    Upgrading and Repairing Networks
    Macromedia Dreamweaver 8 UNLEASHED
    Windows XP Annoyances
    Windows XP Hacks
    Microsoft Windows XP Power Toolkit
    Teach Yourself MS Office In 24Hours
    iPod & iTunes Missing Manual
    PC Hacks 100 Industrial-Strength Tips and Tools
    PC Overclocking, Optimization, and Tuning - 2th Edition
    PC Hardware In A Nutshell 3rd Edition
    PC Hardware in a Nutshell, 2nd Edition
    Upgrading and Repairing PCs
    Google for Dummies
    MySQL Cookbook
    Teach Yourself Macromedia Flash 8 In 24 Hours
    PHP CookBook
    Sams Teach Yourself JavaScript in 24 Hours
    PHP5 Manual
    Free Games Paper Airplanes
    500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele