Example #1
0
def search(query, page=1):
    
    """Retrieves a list of links from Google.
    
    Searches Google for query using SOAP.
    Returns a list of links related to the query.

    """

    o = Output()
    o.mute()

    try:
        data = pygoogle.doGoogleSearch(query, start=(page-1)*10)
        data = [x.URL for x in data.results]
        o.on()
        return data
        
    except pygoogle.NoLicenseKey:
        o.on()
        raise GoogleLicenseError
        
    except Exception, e:
        o.on()
        if dry(): raise GoogleLimitError
        else: raise GoogleError
Example #2
0
def results(query):
    
    """Returns the number of results for the given query.

    This is useful for statistical operations,
    for example querying google for the "grass green",
    "grass yellow", "grass blue" and determining what
    color is most likely associated with "grass".
    
    """

    o = Output()
    o.mute()
    
    try:
        data = pygoogle.doGoogleSearch(query)
        data = data.meta.estimatedTotalResultsCount
        o.on()
        return data
    
    except pygoogle.NoLicenseKey:
        o.on()
        raise GoogleLicenseError
    
    except Exception, e:
        o.on()
        if dry(): raise GoogleLimitError
        else: raise GoogleError
Example #3
0
    def run(self):
        print "\tStarting google service ..."
        # this shoudl be pretty obvious
        # try:
        if 1:
            google.LICENSE_KEY = "orZVQS72I2S7YAdsC6Vy4CdKVmHCWcD9"

            request = string.join(self.words, " ")

            if len(request) == 0:
                self.command.sendMessage(self.sock, "Please supply at least one keyword for the search")
                return

            data = google.doGoogleSearch(request)
            spellcheck = google.doSpellingSuggestion(request)

            print "\tMake output"
            self.command.makeOutput(data, spellcheck)
            self.command.sendMessage(self.sock, self.command.output)