def filterResults(names): outputFile = open("../results.txt", 'a') for name in names: response = query(name, container='dict') time.sleep(0.2) if not response['heading'] and not response['results']: outputFile.write(f"{name}\n")
def search(s): t = '' for i in s: if (i.lower() >= 'a' and i.lower() <= 'z') or (i.lower() >= '0' and i.lower() <= '9') or i == ' ': t += i response = query(t, container='dict') res = [] for i in response['related_topics']: try: res.append(i) except: pass result = [] for i in res: try: result.append(i['text']) except: for j in i['topics']: result.append(j['text']) res = [] for i in range(0, len(result)): res.append((i + 1, result[i])) return res
def main(): # get query term # post_id = request.args.get('id') # call to duckduckgo to get results response = query("paris", container='dict') for n in response['related_topics']: print(n)
def command_wiki(command): result = '' new_list = command.split() if len(new_list) > 1: new_list.pop(0) if len(new_list) > 1: result = query("wiki {}".format(' '.join(new_list)), False, 'namedtuple', False, 'duckduckpy 0.2', True, False, True) if len(new_list) is 1: result = query("{}".format(' '.join(new_list)), False, 'namedtuple', False, 'duckduckpy 0.2', True, False, True) response = result.abstract_url if len(response) > 0: return response else: return "No results found" return "?"
def google_it(q, session_id="general"): response = duckduckpy.query(q, container="dict") if(len(response["related_topics"]) > 0): for result in response["related_topics"]: print("Text: "+result["text"]) print("URL: "+ result["first_url"]) return "Here's some results from DuckDuckGo" else: return "No results found"
def __init__(self, keyword, fullcmd): self.keyword = keyword print(f"searching for {keyword}") try: response = doge.query(keyword) utilities.SpeakText( f'top result on internet says that, {response.related_topics[0].text}' ) except IndexError: pass
def __init__(self, keyword, fullcmd): self.keyword = keyword print(keyword, fullcmd) print(f"searching for {keyword}") if 'search the' not in keyword: try: response = doge.query(keyword) utilities.SpeakText(f'top result on internet says that, {response.related_topics[0].text}') return except IndexError: utilities.SpeakText("I can't seem to find any result for that") return
def search(query): #run wearch query via duckduckgo API response = duckduckpy.query(query, False, 'dict', False, 'duckduckpy 0.2', True, True, False) result = "No results found." if (response["related_topics"] != []): result = (response["related_topics"][0]["text"]) if (response["abstract"] != ""): result = (response["abstract"]) randomText = random.choice(RANDOM_WEBSEARCH) return { "fulfillmentText": randomText[0] + query + ": " + result, "source": "webSearch" }
def process(self, tb, message=None, query=None): if query is not None and message is None: message = query.message text = message.text answer = self.controller.get_answer_for_question(text) if answer is None: self.controller.add_question(message) reply = duckduckpy.query(text) if reply.answer != u'': answer = reply.answer self.controller.add_answer(answer, text) else: answer = "I don't know, but i will figure it out" tb.send_message(message.chat.id, answer) next_node = self.force_move if self.probabilistic: next_node = np.random.choice(self.probabilities.keys(), size=1, p=self.probabilities.values())[0] return next_node
def search(s): t = '' for i in s: if (i.lower() >= 'a' and i.lower() <= 'z') or (i.lower() >= '0' and i.lower() <= '9') or i == ' ': t += i response = query(t, container='dict') res = [] for i in response['related_topics']: try: res.append(i) #['text']) except: pass return response
def teamswebhook(): if request.method == 'POST': json_data = request.json print("\n") print("WEBHOOK POST RECEIVED:") print(json_data) print("\n") webhook_obj = Webhook(json_data) # Details of the message created room = teams_api.rooms.get(webhook_obj.data.roomId) message = teams_api.messages.get(webhook_obj.data.id) person = teams_api.people.get(message.personId) email = person.emails[0] print("NEW MESSAGE IN ROOM '{}'".format(room.title)) print("FROM '{}'".format(person.displayName)) print("MESSAGE '{}'\n".format(message.text)) # Message was sent by the bot, do not respond. # At the moment there is no way to filter this out, there will be in the future me = teams_api.people.me() searchterm = message.text # Check message length to avoid array out of bounds # if len(searchterm) > 11): # if searchterm[:len("Kalah duck ")] == "Kalah duck ": searchterm = searchterm[(len("Kalah ") - 1):] answer = query(searchterm) teams_api.messages.create(room.id, text=answer.abstract) # else: # teams_api.messages.create(room.id, text="Search term too short that's what she said.") # # if message.personId == me.id: # return 'OK' # else: # teams_api.messages.create(room.id, text=searchterm +str(email)) else: print('received none post request, not handled!')
from duckduckpy import query response = query('Python') response.related_topics[0] type(response.related_topics[0]) print(response)
def search_duckduckgo(search_word): response = query(search_word, container="dict")['abstract'] return response
def get_info(self, inp): q = query(inp) return q.abstract
def cmd__s(self, *words): """ Search for <term> Usage: s <term> """ self.info('Searching...') term = ' '.join(words) q = duckduckpy.query(term) self.info() monitor = self.open_monitor(f'Search: {term}') image = getattr(q, 'image', None) if image: slot = monitor.add_slot() self.enqueue(self.show_cover, slot, image) heading = getattr(q, 'heading', None) if heading: monitor.h1(f'{heading}') abstract = getattr(q, 'abstract', None) if abstract: abstract = re.sub(r'</p>', '\n', abstract) abstract = re.sub(r'<br ?/?>', '\n', abstract) abstract = re.sub(r'<[^>]+>', ' ', abstract) monitor.write(f'{abstract}') abstract_url = getattr(q, 'abstract_url', None) if abstract_url: monitor.write(f'{abstract_url}') monitor.clipboard_clear() monitor.clipboard_append(f'{abstract_url}') self.info(f'Copied to clipboard: {abstract_url}') if q.results: monitor.h2('Results') for result in q.results: monitor.write(f'{result.result}') if q.related_topics: monitor.h2('Related topics') for topic in q.related_topics: text = getattr(topic, 'text', None) name = getattr(topic, 'name', None) if text and name: monitor.write(f'{topic.name}: {text}') elif text: monitor.write(f'{topic.text}') elif name: monitor.write(f'{topic.name}') else: monitor.write(f'{topic}') monitor.write(f'{topic}') monitor.hr() monitor.write(f'{q}') return q
def teamswebhook(): # Only execute this section of code when a POST request is sent, as a POST indicates when a message # has been sent and therefore needs processing. if request.method == 'POST': json_data = request.json print("\n") print("WEBHOOK POST RECEIVED:") print(json_data) print("\n") # Pass the JSON data so that it can get parsed by the Webhook class webhook_obj = Webhook(json_data) # Obtain information about the request data such as room, message, the person it came from # and person's email address. room = teams_api.rooms.get(webhook_obj.data.roomId) message = teams_api.messages.get(webhook_obj.data.id) person = teams_api.people.get(message.personId) email = person.emails[0] print("NEW MESSAGE IN ROOM '{}'".format(room.title)) print("FROM '{}'".format(person.displayName)) print("MESSAGE '{}'\n".format(message.text)) # Message was sent by the bot, do not respond. # At the moment there is no way to filter this out, there will be in the future me = teams_api.people.me() if message.personId == me.id: return 'OK' else: pass if message.text[:8] == "@answer ": query_string = message.text[7:] # print(query_string) response = query(query_string) # print(str(response).encode('utf-8')) # print(str(response.abstract_url).encode('utf-8')) url = response.abstract_url # print(str(response.related_topics[0].url).encode('utf-8')) # teams_api.messages.create(room.id, text=response.related_topics[0].text) if response.abstract_text: teams_api.messages.create(room.id, text=response.abstract_text) else: teams_api.messages.create(room.id, text=response.related_topics[0].text) teams_api.messages.create(room.id, text='Read more: {}'.format(url)) elif message.text[:10] == "@calendar ": if message.text == "@calendar tomorrow": events = CalendarQuery.tomorrow(ci) print_events(webhook_obj, events) elif re.match('@calendar\snext\s\d+', message.text) is not None: num_events = int(message.text.rsplit(' ', 1)[1]) events = CalendarQuery.next_events(ci, num_events) print_events(webhook_obj, events) elif message.text == "@calendar next": events = CalendarQuery.next_events(ci, 10) print_events(webhook_obj, events) elif message.text == "@calendar today": events = CalendarQuery.today(ci) print_events(webhook_obj, events) elif message.text[:13] == "@availability": if message.text == "@availability": best_dates, people_that_agree = parser.get_best_date() if not best_dates: teams_api.messages.create(room.id, text='There is no availability information available.') else: teams_api.messages.create(room.id, text='The best day for a meeting is: {}'.format(str(best_dates[0]))) if people_that_agree: teams_api.messages.create(room.id, text='The following teammates confirmed they are available: {}'.format(', '.join(list(set(people_that_agree))))) if message.text == "@availability reset": parser.reset_date() if re.match('@availability\screate\s-start\s\d+\s-end\s\d+', message.text) is not None: parts = message.text.split(' ') start_time = datetime.datetime.combine(parser.get_best_date()[0][0], datetime.datetime.min.time()) + datetime.timedelta(hours = int(parts[3])) end_time = datetime.datetime.combine(parser.get_best_date()[0][0], datetime.datetime.min.time()) + datetime.timedelta(hours = int(parts[5])) existing_events = ci.get_events(start_time=start_time, end_time=end_time) print(start_time) print(end_time) if existing_events: teams_api.messages.create(room.id, text='An event already exists at that time.') print_events(webhook_obj,existing_events) else: ci.add_event(summary = "Meeting by @calendar_bot", start_time = start_time, end_time = end_time) teams_api.messages.create(room.id, text='Meeting setup succesful.') else: print(parser.extract(message.text)) parser.manage_text(message.text) print(parser.get_best_date())
from duckduckpy import query response = query('USA') # namedtuple is used as a container #print(response) res = response.result print(res)
''' Install below Python Module before You run this code. >>> pip install duckduckpy --upgrade # DuckDuckPy is a Python library for querying DuckDuckGo API and render results either to Python dictionary or namedtuple. ''' from duckduckpy import query print("\n *** DuckDuckGo Search *** \n") search = input(' Enter text to Search in DuckDuckGo: ') response = query(search) print(f'\n Response -> {response}') print(f'\n Response.related_topics[0] -> {response.related_topics[0]}')
from duckduckpy import query response = query('украина https://t.me/', container='dict') print(response['related_topics'])