def get_answer(self, question): # We try to find an answer in all of our services possible_answers = {} corrected_question = spell_check(question) entities = get_entities(corrected_question) # First, we try to find an answer in our local AIML files possible_answers["AIML"] = aiml_response(corrected_question) if not self._multiple_answers and possible_answers["AIML"] != "": return possible_answers["AIML"] # We search on Wikipedia only if the question starts with `WHO` or `WHAT`; # but if it is too ambiguous, we still perform a Google Search. if "WP" in entities.values(): search_words = "" for k, v in entities.iteritems(): if v.startswith('NN'): search_words += k + " " possible_answers["Wikipedia"] = wikipedia_search(search_words[:-1]) if possible_answers["Wikipedia"] == "": possible_answers["Google"] = google_search(corrected_question) if not self._multiple_answers and possible_answers[ "Wikipedia"] != "": return possible_answers["Wikipedia"] if not self._multiple_answers and possible_answers["Google"] != "": return possible_answers["Google"] # We search on Google only if the question starts with `WHERE`, `WHEN`, `WHOSE`, `WHICH`. if any(pronoun in entities.values() for pronoun in ["WDT", "WP$", "WRB"]): possible_answers["Google"] = google_search(corrected_question) if not self._multiple_answers and possible_answers["Google"] != "": return possible_answers["Google"] if not self._multiple_answers: return "What? I even don't know how to answer. Maybe you tell me!?" else: answer = "" for k, v in possible_answers.iteritems(): if v != "": answer += v + " ({})\n".format(k) answer = answer[:-1] if answer == "": answer = "What? I even don't know how to answer. Maybe you tell me!?" return answer
def perform_google_search(): search_term = "+".join(message.content.split()[1:]) try: results, moreResultsUrl = google_search.google_search( search_term) print results except TypeError: print "No results" message.message.reply("No results were found for " + message.content[9:]) return print message.content print search_term message.message.reply("Search results for **%s**: " % message.content[9:]) # sould be configurable count = len(results) < 3 and len(results) or 3 for i in range(0, count): res = results[i] room.send_message( "[%s](%s)" % (res['titleNoFormatting'], res['unescapedUrl'])) room.send_message( chaterize_message(res["content"]).replace("\n", " ")) room.send_message("[See More...](%s)" % moreResultsUrl)
def get(self): searchstr = self.get_argument("search_text") page = int(self.get_argument("page")) rsz = int(self.get_argument("rsz")) print 'searching:', searchstr results = google_search(searchstr, page, rsz) nextpage = 1 if len(results) >= 8: nextpage = page + 1 self.render("search_results.html", results=results, searchstr = searchstr, page = page, nextpage = nextpage)
def get_scholar_venues(): # Searches for all venues gotten through google scholar on dblp. venues = db.get_scholar_venues() for v in venues: venue = v[0] if "Journal" in venue: continue s = get_html(link_base_dblp + venue) names = s.findAll("venue") hits = s.findAll("url") for h in hits: if not h.text.startswith("htt"): hits.remove(h) solid_hit = 0 for name, hit in zip(names, hits): title = name.text url = hit.text similarity = similar(venue, title) if similarity >= 0.8: solid_hit = 1 if "/conf" in url: db.add_venue(title, url) break if solid_hit == 0: searching_term = "dblp " + venue search_results = google_search(searching_term) urls = [] for result in search_results: url = result['link'] if url.endswith("/index"): if "/conf" in url: db.add_venue(venue, url) break urls.append(url) print("No match for", venue) for url in urls: # For last resort manual adding if "https://dblp.org/db/conf" in url: print(url)
def search_google(self): """ search on google and create/update the search_keyword in db. :return: Top 5 links """ google_query = self.command[1].lower() # search on Google API results = google_search(google_query) if results: # Check if the data already exists and then create/update the data. self.create_update_db(google_query) results = ' \n'.join(results) return "The Top five links for your search are -\n{links}".format( links=results) else: return "Sorry, there are no matching Links found"
def search(): status_code = 200 query = request.args.get('query') info = {} if 'timespan' not in cache: cache['timespan'] = {} if 'timespan' in cache and query in cache['timespan']: info = cache['timespan'][query] else: info = google_search.google_search(query) cache['timespan'][query] = info with open('cache.json', 'w') as f: json.dump(cache, f, indent=4, sort_keys=True, default=str) is_left = True for data in info['results']: data['position'] = 'left' if is_left else 'right' is_left = not is_left return render_template("index.html", **info)
def main(args): #these will be default until command-line arguments are supported query = 'hummus' website = 'allrecipes.com' #Set our allrecipes search result url. in this case we are searching for hummus recipes search_results_url='http://allrecipes.com/search/default.aspx?qt=k&wt='+query+'&rt=r&origin=Home%20Page' #create browser br=create_browser() gs = google_search.google_search(website,query,MAX_SEARCH_ENTRIES) gs.loop_until_complete() results_list = gs.results_list results_list = [x for x in results_list if allrecipes.validate_url(x)] #get list of recipe url's from search results if False: results_list = read_search_results(search_results_url,br) print "READING INFO FROM RECIPE PAGES" #read info from all the recipe pages in to a dict recipe_info_dict = read_recipe_pages(results_list,br,query) write_info_to_database(recipe_info_dict)
def perform_google_search(): search_term = "+".join(message.content.split()[1:]) try: results, moreResultsUrl = google_search.google_search(search_term) print results except TypeError: print "No results" message.message.reply("No results were found for " + message.content[9:]) return print message.content print search_term message.message.reply("Search results for **%s**: " % message.content[9:]) # sould be configurable count = len(results) < 3 and len(results) or 3 for i in range(0, count): res = results[i] room.send_message("[%s](%s)" % (res['titleNoFormatting'], res['unescapedUrl'])) room.send_message(chaterize_message(res["content"]).replace("\n", " ")) room.send_message("[See More...](%s)" % moreResultsUrl)
def main(): query_string = raw_input("Enter keywords seperated by space \n -->") keywords = query_string.split(' ') print 'Performing Bing search...' bing_images_links = [image['url'] for image in bing_search(keywords)] print 'Done.' print 'Performing Giphy search...' gifs_links = giphy_search(keywords) print 'Performing Google search...' google_images_links = google_search(keywords) print 'Performing Twitter tweets search...' twitter_text = [tweet[2] for tweet in get_tweets(keywords, media=False)] print 'Performing Twitter media search...' twitter_images_links = [] try: for tweet in get_tweets(keywords, media=True): if len(tweet)==4: twitter_images_links.append(tweet[3]) except: pass print 'Done performing searches.' print 'Printing out the results' print_links('Bing', bing_images_links) print_links('Giphy', gifs_links) print_links('Google', google_images_links) print_links('Twitter', twitter_text) print_links('Twitter Media', twitter_images_links)
async def bot_google_search(ctx, *args): # validate user input if not args: await ctx.send(env.INPUT_REQUIRED_MSG) else: search_keyword = ' '.join(args) # validate if input is less than or equal to max length if len(search_keyword) > env.SEARCH_KEY_MAX_LENGTH: await ctx.send(env.MAX_INPUT_LENGTH_MSG) else: # create entry in database db.create_search_history(ctx.message.author.id, search_keyword) # get result from google api results = gs.google_search(search_keyword) if not results: await ctx.send(env.NO_SEARCH_RESULT_MSG) for result in results: embed = discord.Embed(title=result.get('title'), url=result.get('link'), description=result.get('description'), color=discord.Color.purple()) await ctx.send(embed=embed)
def baike_search(usersay): usersay = usersay + u' 百科' baike_search = google_search(usersay) return google_search
def baike_search(usersay): usersay = usersay + u' 百科' baike_search = google_search(usersay) return baike_search
import pprint, google_search pprint.pprint(google_search.google_search("高中 网站", 5))