Beispiel #1
0
    def do_search(self, search_term):
        """ Perform paged searches while we find new FQDN """

        print(search_term)

        custom_params = {'safeSearch': 'Off'}
        if self.args.offset:
            custom_params['offset'] = self.args.offset

        search_service = MsWeb(self.args.bing_api_key,
                               query=search_term,
                               custom_params=custom_params)

        bing_results = search_service.search(limit=self.args.limit,
                                             format='json')
        self.query_count += 1
        results = BingSearch._parse_results(bing_results)

        # Find all the things until we can't find new URLs anymore
        # We have the first result set, do a new search and compare it to the previous one.
        if self.args.find_all and self.query_count < self.args.max_queries:

            result_set = set((x["url"] for x in results))

            # Internal py_ms_cognitive object deals with the offset
            bing_results = search_service.search(limit=self.args.limit,
                                                 format='json')
            self.query_count += 1
            new_results = BingSearch._parse_results(bing_results)

            new_result_set = set((x["url"] for x in new_results))

            # New result contains everything already inside result_set
            while not result_set.issuperset(new_result_set):

                results += new_results

                if self.query_count < self.args.max_queries:
                    # Internal py_ms_cognitive object deals with the offset
                    bing_results = search_service.search(limit=self.args.limit,
                                                         format='json')
                    self.query_count += 1
                    new_results = BingSearch._parse_results(bing_results)

                    new_result_set = set((tuple(x) for x in results))

                else:
                    # Do not perform a search, but previous results were added
                    # Stop looping, exit
                    break

        return results
Beispiel #2
0
 def test_can_silent_fail_web_search(self):
     web_bing = PyMsCognitiveWebSearch(SECRET_KEY,
                                       "Python Software Foundation",
                                       silent_fail=True)
     result_one = web_bing.search(limit=50)
     self.assertTrue(len(result_one) == 50)
     self.assertTrue("python" in result_one[0].name.lower())
Beispiel #3
0
 def test_empty_response(self):
     '''
     This test checks that searching for a non-existent keyword will not error out.
     '''
     non_existing_result = u'youwillmostdeffinitlynotfindthisveryweirdandlongstringopnanysitewhatsoever123'
     web_bing = PyMsCognitiveWebSearch(SECRET_KEY, non_existing_result)
     self.assertTrue([] == web_bing.search())
Beispiel #4
0
def run_query(search_terms):
    bing_api_key = read_bing_key()
    if not bing_api_key:
        raise KeyError("Bing Key Not Found")

    # Create our results list which we'll populate.
    results = []
    # Custom params
    params = 'mkt=ru-RU'

    try:
        search_service = PyMsCognitiveWebSearch(bing_api_key, search_terms, custom_params=params)
        json_response = search_service.search(limit=11, format='json')  # 1 - 10

    except:
        print("Error when querying the Bing API")

    # Loop through each page returned, populating out results list.
    # dict_keys(['json', 'deep_links', 'snippet', 'url', 'title', 'name', 'description', 'id', 'display_url'])
    for idx in range(11):
        results.append({'title': json_response[idx].title,
                        'link': json_response[idx].display_url,
                        'summary': json_response[idx].description})

    return results
def find_omim_link(row):
    geneName = safely_convert_val_to_str(
        row['Gene Symbol'])  #search based on the ingenuity assigned gene name
    searchTerm = 'omim ' + geneName
    search_service = PyMsCognitiveWebSearch(bingWebSearchKey, searchTerm)
    firstFiftyResults = search_service.search(limit=50, format='json')
    url = find_first_correct_result_url(firstFiftyResults, 'omim')
    return url
Beispiel #6
0
def azure_search(claim):
    search_term = claim
    search_service = PyMsCognitiveWebSearch('75d1a40af4bf4ba4bdf561ae25b5db5c',
                                            claim)
    first_three_result = search_service.search(limit=3, format='json')  #1-50

    urls = []
    # To get individual result json:
    for i in first_three_result:
        urls.append(i.url.encode('utf-8'))
    return urls
Beispiel #7
0
    def get_seed(self, search_term):
        search_service = PyMsCognitiveWebSearch(config.key, search_term)
        first_twenty_result = search_service.search(limit=10,
                                                    format='json')  #1-10

        for i in range(10):
            #Giving Each of the 10 links a pagerank of 0.1 (i.e. 1/10)
            link = first_twenty_result[i].json['displayUrl']
            link = self.normalize(link)
            self.nodesToVisit.put(
                (-0.1,
                 link))  #Negate for priority queue to favor higher pagerank
            self.bfs_queue.put(link)
            self.ranks[link] = 0.1
Beispiel #8
0
def run_query(search_terms):
    bing_api_key = read_bing_key()
    if not bing_api_key:
        raise KeyError('Bing Key Not Found')
    results_per_page = 10

    results = []

    try:
        search_service = PyMsCognitiveWebSearch(bing_api_key, search_terms)
        response = search_service.search(limit=results_per_page, format='json')

        for result in response:
            results.append({
                'title': result.json['name'],
                'link': result.json['displayUrl'],
                'summary': result.json['snippet']})
    except:
        print("Error when querying the Bing API")

    return results
Beispiel #9
0
from py_ms_cognitive import PyMsCognitiveWebSearch

search_term = "Amy Burkhardt"
search_service = PyMsCognitiveWebSearch(
    "a185959d275247529ba4bb965f9f56ce",
    '"Five-star technology solutions" AND "New York City Department of Education" AND assessment'
)
first_result = search_service.search(limit=1, format='json')  # 1-50
print(first_result[0].title)
print(first_result[0].url)

print('hello world')
def query(query):
    search_service = PyMsCognitiveWebSearch(keys.get('bing_api_key'), query)
    first_fifty_result = search_service.search(limit=10, format='json')  #1-50
    return [(x.name, x.display_url) for x in first_fifty_result]
Beispiel #11
0
def query(query):
    search_service = PyMsCognitiveWebSearch(keys.get('bing_api_key'), query)
    first_fifty_result = search_service.search(limit=10, format='json') #1-50
    return [(x.name, x.display_url) for x in first_fifty_result]
print "Status: 200 OK"

form = cgi.FieldStorage()
query = form.getvalue('query')

logfile.write(query)
logfile.write("\n")

#query = "moon snails"

API_KEY = "54bcf3e9f555466fa24f529b88311f65"
search_term = query
limit = 10
search_array = search_term.split()
search_service = PyMsCognitiveWebSearch(API_KEY, search_term)
results = search_service.search(limit=limit, format='json')
x = 0
h = 550
w = 550

freq_array = []
url_array = []
name_array = []
snippet_array = []

for x in range(0, limit):
    try:
        dirty_url = results[x].url[20:]
        clean_url = dirty_url[dirty_url.find("http"):]
        clean_url = clean_url[:clean_url.find("&p=DevEx")]
        clean_url = urllib.unquote(clean_url)
Beispiel #13
0
def search(query):
    bing_web = PyMsCognitiveWebSearch(key, query)
    bing_Image = PyMsCognitiveImageSearch(key, query)
    first_ten_result = bing_web.search(limit=10, format='json')  #1-10
    first_ten_image = bing_Image.search(limit=10, format='json')  #1-10
    return (first_ten_image[0].content_url)
Beispiel #14
0
from py_ms_cognitive import PyMsCognitiveWebSearch, PyMsCognitiveImageSearch

key = '82af3a845a3640318879cf8d6db7320a'
query = "New York City"
bing_web = PyMsCognitiveWebSearch(key, query)
bing_Image = PyMsCognitiveImageSearch(key, query)
first_ten_result = bing_web.search(limit=10, format='json')  #1-10
first_ten_image = bing_Image.search(limit=10, format='json')  #1-10

print(first_ten_image[0].name)