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)
google_web_results = google_web_searcher.query(test_query_str) google_web_timing = time.time() - t print 'Retrieved %d results in %f seconds' % (len(google_web_results), google_web_timing) result_page_gen.gen_results_page(google_web_results, 'GoogleWebSearch()', os.path.join(outdir, 'google_web_results.html'), show_in_browser=False) all_results.append(google_web_results) all_generator_names.append('GoogleWebSearch()') if test_flickr_api: flickr_api_searcher = image_query.FlickrAPISearch() print 'Executing Flickr API Search...' t = time.time() flickr_api_results = flickr_api_searcher.query(test_query_str) flickr_api_timing = time.time() - t print 'Retrieved %d results in %f seconds' % (len(flickr_api_results), flickr_api_timing) result_page_gen.gen_results_page(flickr_api_results, 'FlickrApiSearch()', os.path.join(outdir, 'flickr_api_results.html'), show_in_browser=False) all_results.append(flickr_api_results) all_generator_names.append('FlickrAPISearch()')