def ddgSearch(searchQuery): r = ddg3.query(searchQuery) print(r.type) if(r.type == 'disambiguation'): print("Here are the first couple results related to what you said:") print(r.related[0].text) info = "\n" + r.related[0].text info = info + "\n" + r.related[0].url print(r.related[1].text) info = info + "\n" + r.related[1].text info = info + "\n" + r.related[1].url textPrompt(info) elif(r.type == 'answer'): print(r.abstract.text) info = "\n" + r.abstract.text info = info + "\n" + r.abstract.url textPrompt(info) elif(r.type == 'nothing'): print("Here are some results related to your search:") print(r.related) info = "\n" + r.related textPrompt(info)
async def search(self, ctx, *args): """ Search the web, uses DuckDuckGo for privacy """ r = ddg3.query("'{0}'".format(args)) result_type = '' result_type = r.type #answer results #answer_text = r.results[0].text #answer_url = r.results[0].url #disambiguation results result_text = r.related[0].text result_url = r.related[0].url embed = discord.Embed( description="Search results for {0}, {1}".format(args, ctx.message.author.mention), # change color to match other embeds color=3447003, title='Here are your results', ) # footer message embed.set_footer(text="Via .search @ {0} | Results via DuckDuckGo".format(datetime.datetime.now().strftime("%H:%M"))) # select which output is received and display it in the embed if result_type is 'answer': embed.add_field(name="__" + "Search Results" + "__", value="URL: {0} \n {1}" \ .format(r.results[0].url, r.results[0].text)) else: embed.add_field(name="__" + "Search Results" + "__", value="URL: {0} \n {1}" \ .format(result_url, result_text)) await ctx.channel.send(embed=embed)
def search(text): result = ddg3.query(text) search_results = [] if result.abstract.text: search_results.append( { "type": "TEXT", "body": result.abstract.text, "title": "Main Abstract", "confidence": 1.0, } ) if result.results: search_results.extend( [ { "type": "TEXT", "body": "%s - %s" % (r.text, r.url), "title": "Search Result %s" % (index,), "confidence": ((len(result.results) - index) / 10), } for index, r in enumerate(result.results) ] ) return search_results
def buscar(dadoBuscado): busca = ddg3.query(dadoBuscado) dict_ = list() for dado in range(len(busca.related)): resultado = dict() resultado["Título"] = busca.related[dado].text resultado["URL"] = busca.related[dado].url dict_.append(resultado) return dict_
def get_answer(self): r = ddg3.query(self.query) if (r.answer is not None and "HASH" not in r.answer.text and r.answer.text): return r.answer.text elif len(r.abstract.text) > 0: return r.abstract.text.split('. ')[0] + "." elif len(r.related) > 0 and len(r.related[0].text) > 0: return r.related[0].text else: return None
def get_duckduckgo_search_links(keyword): r = ddg3.query(keyword) print(type(r)) print(r.results[1].url) links = [] # search = duckpy.search(keyword) # print(search) # links = [] # results = search['results'] # for result in results: # links.append(result['url']) return links
async def fact(self, ctx, *, search_term: str = None): """ Search for a fact! Use this command in combination with a subject you like to get a fact for that subject """ if search_term is None: embed = discord.Embed(title='{}:'.format(ctx.message.author.name), description='You really should reconsider reading the **`{}help fact`**'.format(self.config['prefix']), colour=0xf20006) a = await self.bot.say(embed=embed) await self.bot.add_reaction(a, self.emojiUnicode['warning']) return search_term = search_term.lower() if search_term == "botzilla": embed = discord.Embed(title='{}:'.format(ctx.message.author.name), description='Best bot on the market right now! \nNo need for more information!', colour=0xf20006) a = await self.bot.say(embed=embed) await self.bot.add_reaction(a, '\U0001f44c') return try: search_number = random.randint(0, 1) r = duckduckgo3.query(search_term) related_type = r.type related_text = r.related[search_number].text 'Python (programming language), a computer programming language' related_related = r.related[search_number].url message2user = "******" % (related_type, related_text, related_related) embed = discord.Embed(title='{}:'.format(ctx.message.author.name), description='{}'.format(message2user), colour=0xf20006) a = await self.bot.say(embed=embed) await self.bot.add_reaction(a, self.emojiUnicode['succes']) return except IndexError: embed = discord.Embed(title='{}:'.format(ctx.message.author.name), description='Nothing found...', colour=0xf20006) a = await self.bot.say(embed=embed) await self.bot.add_reaction(a, self.emojiUnicode['warning']) return
def respond(self, query): if len(query) == 0: return 0.0 if self.autotranslate and self.lang[:2] != 'en': query_tr = translate(query, from_language=self.lang[:2], to_language='en') self.log.debug("translation: {}".format(query_tr)) r = ddg.query(query_tr) LOG.debug('Query: ' + str(query)) LOG.debug('Query_tr: ' + str(query_tr)) LOG.debug('Type: ' + r.type) if (r.answer is not None and r.answer.text and "HASH" not in r.answer.text): LOG.debug('Answer: ' + str(r.answer.text)) if self.autotranslate and self.lang[:2] != 'en': response = translate(r.answer.text, from_language='en', to_language=self.lang[:2]) else: response = r.answer.text return (query + self.is_verb + response + '.') elif len(r.abstract.text) > 0: LOG.debug('Abstract: ' + str(r.abstract.text)) sents = split_sentences(r.abstract.text) if self.autotranslate and self.lang[:2] != 'en': for sent in sents: sent = translate(sent, from_language='en', to_language=self.lang[:2]) return sents[0] elif len(r.related) > 0 and len(r.related[0].text) > 0: related = split_sentences(r.related[0].text)[0] answer = self.format_related(related, query) LOG.debug('Related: ' + str(answer)) if self.autotranslate and self.lang[:2] != 'en': answer = translate(answer, from_language='en', to_language=self.lang[:2]) return (answer) else: return None
def respond(self, query): if len(query) == 0: return 0.0 r = ddg.query(query) LOG.debug('Query: ' + str(query)) LOG.debug('Type: ' + r.type) if (r.answer is not None and r.answer.text and "HASH" not in r.answer.text): return (query + self.is_verb + r.answer.text + '.') elif len(r.abstract.text) > 0: sents = split_sentences(r.abstract.text) return sents[0] elif len(r.related) > 0 and len(r.related[0].text) > 0: related = split_sentences(r.related[0].text)[0] return (self.format_related(related, query)) else: return None