#!/usr/bin/python
# googly.py
# A typical Google Web API Python script using Mark Pilgrim's
# PyGoogle Google Web API wrapper
# [http://diveintomark.org/projects/pygoogle/].
# Usage: python googly.py <query>
import sys, string, codecs
# Use the PyGoogle module.
import google
# Grab the query from the command line
if sys.argv[1:]:
query = sys.argv[1]
else:
sys.exit('Usage: python googly.py <query>')
# Your Google API developer's key.
google.LICENSE_KEY = 'insert key here'
# Query Google.
data = google.doGoogleSearch(query)
# Teach standard output to deal with utf-8 encoding in the results.
sys.stdout = codecs.lookup('utf-8')[-1](sys.stdout)
# Output.
for result in data.results:
print string.join( (result.title, result.URL, result.snippet), "\n"), "\n"