Esempio n. 1
0
def imsearch_query(query, engine, query_params, query_timeout=-1.0):
    # prepare input arguments for searcher initialization if non-default
    searcher_args = dict()
    if query_timeout > 0.0:
        searcher_args['timeout'] = query_timeout
    # initialize searcher
    if engine == 'bing_api':
        searcher = image_query.BingAPISearch(**searcher_args)
    elif engine == 'google_old_api':
        searcher = image_query.GoogleOldAPISearch(**searcher_args)
    elif engine == 'google_api':
        searcher = image_query.GoogleAPISearch(**searcher_args)
    elif engine == 'google_web':
        searcher = image_query.GoogleWebSearch(**searcher_args)
    elif engine == 'flickr_api':
        searcher = image_query.FlickrAPISearch(**searcher_args)
    else:
        raise ValueError('Unkown query engine')
    # execute the query
    return searcher.query(query, **query_params)
Esempio n. 2
0
    google_old_api_timing = time.time() - t
    print 'Retrieved %d results in %f seconds' % (len(google_old_api_results),
                                                  google_old_api_timing)

    result_page_gen.gen_results_page(google_old_api_results,
                                     'GoogleOldAPISearch()',
                                     os.path.join(
                                         outdir,
                                         'google_old_api_results.html'),
                                     show_in_browser=False)

    all_results.append(google_old_api_results)
    all_generator_names.append('GoogleOldAPISearch()')

if test_google_api:
    google_api_searcher = image_query.GoogleAPISearch()
    print 'Executing Google API Search (Custom Search)...'
    t = time.time()
    google_api_results = google_api_searcher.query(test_query_str)
    google_api_timing = time.time() - t
    print 'Retrieved %d results in %f seconds' % (len(google_api_results),
                                                  google_api_timing)

    result_page_gen.gen_results_page(google_api_results,
                                     'GoogleAPISearch()',
                                     os.path.join(outdir,
                                                  'google_api_results.html'),
                                     show_in_browser=False)

    all_results.append(google_api_results)
    all_generator_names.append('GoogleAPISearch()')