def define(bot, trigger): """ Da la definición de un término segun rae. """ if not trigger.group(2): bot.say(trigger.nick + ': debes indicar un término a buscar en el diccionario.') return try: word = trigger.group(2) client = Client('http://dirae.es/static/opensearch.xml') results = client.search(word) max = 0 for result in results: max = max + 1 if result.title == word: output = result.summary url = 'http://lema.rae.es/drae/srv/search?val='+word elif max > 3: break if output: bot.say(output.replace('<em>', '\002').replace('</em>', '\002')) bot.say(url) else: bot.say('No he encontrado ese término!') except Exception as e: bot.say(trigger.nick + ': No pude obtener la definición de ese término, lo siento.') print "{error}: {msg}".format(error=type(e), msg=e)
def test_query(self): client = Client(ClientTests.url) self.assertEqual( client.agent, 'python-opensearch <https://github.com/edsu/opensearch>') results = client.search("computer") self.assertTrue(results.totalResults > 0)
def define(bot, trigger): """ Da la definición de un término segun rae. """ if not trigger.group(2): bot.say(trigger.nick + ': debes indicar un término a buscar en el diccionario.') return try: word = trigger.group(2) client = Client('http://dirae.es/static/opensearch.xml') results = client.search(word) max = 0 for result in results: max = max + 1 if result.title == word: output = result.summary url = 'http://lema.rae.es/drae/srv/search?val='+word elif max > 3: break if output: bot.say(output.replace('<em>', '\002').replace('</em>', '\002')) bot.say(url) else: bot.say('No he encontrado ese término!') except Exception as e: bot.say(trigger.nick + ': No pude obtener la definición de ese término, lo siento.') print "{error}: {msg}".format(error=type(e), msg=e)
def search(request): """Search the repository for the given terms.""" client = OpenSearchClient(OPENSEARCH_URL) terms = urllib.unquote(request.params.get('q', '')).decode('utf8') results = client.search(terms) records = [] for result in results: records.append({'title': result.title, 'link': _fix_url(result.link), 'summary': result.summary_detail['value'], }) return {'records': records, 'q': terms, }
def search(request): client = OpenSearchClient(OPENSEARCH_URL) terms = urllib.unquote(request.GET.get('q', '')).decode('utf8') results = client.search(terms) records = [] for result in results: records.append({'title': result.title, 'link': _fix_url(result.link), 'summary': result.summary_detail['value'], }) return render_to_response('moduleviewer/search.html', {'title': SITE_TITLE, 'records': records, 'search_terms': request.GET.get('q'), })
def test_query(self): client = Client(ClientTests.url) self.assertEqual(client.agent, 'python-opensearch <https://github.com/edsu/opensearch>') results = client.search("computer") assert(results.totalResults > 0)
#!/usr/bin/env python __author__ = "mlecarme" import sys here = sys.path[0] sys.path.remove(here) from opensearch import Client sys.path.insert(0, here) HOST = 'localhost' PORT = 8001 c = Client('http://%s:%i/opensearch-description' % (HOST, PORT)) resp = c.search(sys.argv[1]) for r in resp: print r
def tryaquery(self): client = Client('http://geekscruff.me/opensearch/VIAFallFieldsSearch.xml') results = client.search("jane austen") for result in results: print result.title, result.link
#!/usr/bin/env python # this python script walks all the opensearch servers # and tries to exercise them, and report any errors # # Rob Sanderson <*****@*****.**> from opensearch import Client import socket, urllib2 socket.setdefaulttimeout(10) # OS list of open OS targets mainc = Client('http://a9.com/-/opensearch/public/osd') mainres = mainc.search('') # fetch all for site in mainres: print "Trying: %s" % site.link try: c = Client(site.link) except socket.timeout: print " ... timed out" continue except urllib2.URLError: print " ... timed out" continue except: print " ... ERROR: couldn't create Client" continue q = c.description.samplesearch if not q: q = "cat"