def fetchFirstResult(self, query): """ Given a query, find the first Google result, and downloads that page. Returns a Deferred which will be called back with a tuple containing (firstMatchUrl, firstMatchPageData) """ # the twisted.web.google.checkGoogle function does an # "I'm feeling lucky" search on Google return google.checkGoogle(query).addCallback(self._gotUrlFromGoogle)
def fetchFirstResult(self, query): """ Given a query, find the first Google result, and downloads that page. Returns a Deferred which will be called back with a tuple containing (firstMatchUrl, firstMatchPageData) """ # the twisted.web.google.checkGoogle function does an # "I'm feeling lucky" search on Google return google.checkGoogle(query).addCallback( self._gotUrlFromGoogle)
def testCheckGoogle(self): raise unittest.SkipTest("no violation of google ToS") d = google.checkGoogle('site:www.twistedmatrix.com twisted') d.addCallback(self.assertEquals, 'http://twistedmatrix.com/') return d
from twisted.web.google import checkGoogle from twisted.python.util import println from twisted.internet import reactor import sys checkGoogle(sys.argv[1:]).addCallbacks( lambda l:(println(l),reactor.stop()), lambda e:(println('error:',e),reactor.stop())) reactor.run()
def google(self,requestobj,data): checker = checkGoogle(data) checker.addCallback( lambda l: (requestobj.send(l), reactor.stop()) )
def testCheckGoogle(self): raise unittest.SkipTest("no violation of google ToS") d = google.checkGoogle('site:www.twistedmatrix.com twisted') r = unittest.deferredResult(d) self.assertEquals(r, 'http://twistedmatrix.com/')
def testCheckGoogle(self): raise unittest.SkipTest("no violation of google ToS") d = google.checkGoogle('site:www.twistedmatrix.com twisted') d.addCallback(self.assertEqual, 'http://twistedmatrix.com/') return d
from twisted.web.google import checkGoogle from twisted.python.util import println from twisted.internet import reactor import sys checkGoogle(sys.argv[1:]).addCallbacks( lambda l: (println(l), reactor.stop()), lambda e: (println('error:', e), reactor.stop())) reactor.run()