def __init__(self, params): for k, v in params.items(): if isinstance(v, GoogleSOAPFacade.structType): v = GoogleSOAPFacade.toDict( v ) try: if isinstance(v[0], GoogleSOAPFacade.structType): v = [ SOAPProxy.toDict( node ) for node in v ] except: pass self.__dict__[str(k)] = v
def doGoogleSearch( q, start = 0, maxResults = 10, filter = 1, restrict='', safeSearch = 0, language = '', inputencoding = '', outputencoding = '',\ license_key = None, http_proxy = None ): """ Search Google using the SOAP API and return the results. You need a license key to call this function; see the U{Google APIs <http://www.google.com/apis/>} site to get one. Then you can either pass it to this function every time, or set it globally; see the L{google} module-level docs for details. See U{http://www.google.com/help/features.html} for examples of advanced features. Anything that works at the Google web site will work as a query string in this method. You can use the C{start} and C{maxResults} parameters to page through multiple pages of results. Note that 'maxResults' is currently limited by Google to 10. See the API reference for more advanced examples and a full list of country codes and topics for use in the C{restrict} parameter, along with legal values for the C{language}, C{inputencoding}, and C{outputencoding} parameters. You can download the API documentation U{http://www.google.com/apis/download.html <here>}. @param q: search string. @type q: String @param start: (optional) zero-based index of first desired result. @type start: int @param maxResults: (optional) maximum number of results to return. @type maxResults: int @param filter: (optional) flag to request filtering of similar results @type filter: int @param restrict: (optional) restrict results by country or topic. @type restrict: String @param safeSearch: (optional) @type safeSearch: int @param language: (optional) @type language: String @param inputencoding: (optional) @type inputencoding: String @param outputencoding: (optional) @type outputencoding: String @param license_key: (optional) the Google API license key to use @type license_key: String @param http_proxy: (optional) the HTTP proxy to use for talking to Google @type http_proxy: String @return: the search results encapsulated in an object @rtype: L{SearchReturnValue} """ license_key = getLicense( license_key ) http_proxy = getProxy( http_proxy ) remoteserver = _getRemoteServer( http_proxy ) filter = _marshalBoolean( filter ) safeSearch = _marshalBoolean( safeSearch ) data = remoteserver.doGoogleSearch( license_key, q, start, maxResults, filter, restrict, safeSearch, language, inputencoding, outputencoding ) metadata = GoogleSOAPFacade.toDict( data ) del metadata["resultElements"] metadata = SearchResultsMetaData( metadata ) results = [ SearchResult( GoogleSOAPFacade.toDict( node ) ) \ for node in data.resultElements ] return SearchReturnValue( metadata, results )