Google filter

Submitted by ormiret on Sun, 02/01/2011 - 02:07.

My method of naming things is to use a random word generator to come up with something I like the sound of. Some of the words it generates already exist though so I made a script to filter input to only the lines (which in my use case are words from the random word generator) that get no results from google.

The python script:

# Read lines from stdin and output those that get no results from google

import urllib
import simplejson
import sys

for word in sys.stdin.readlines():
    query = urllib.urlencode({'q': word})
    url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % query
    search_results = urllib.urlopen(url)
    json = simplejson.loads(search_results.read())
    results = json['responseData']['results']
    if len(results) == 0:
        print word

( categories: )