From 249bbf7f8b15dee2201112b85742d8160bea0a8b Mon Sep 17 00:00:00 2001 From: aahill Date: Mon, 10 Sep 2018 14:48:22 -0700 Subject: [PATCH] adding new Bing Image Search quickstart sample (#16) * adding new Bing Image Search quickstart sample * updating sample --- samples/search/image-search-quickstart.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 samples/search/image-search-quickstart.py diff --git a/samples/search/image-search-quickstart.py b/samples/search/image-search-quickstart.py new file mode 100644 index 0000000..282b2ab --- /dev/null +++ b/samples/search/image-search-quickstart.py @@ -0,0 +1,23 @@ +from azure.cognitiveservices.search.imagesearch import ImageSearchAPI +from msrest.authentication import CognitiveServicesCredentials + +subscription_key = "Enter your key here" +search_term = "canadian rockies" + +""" +This application will search images on the web with the Bing Image Search API and print out first image result. +""" +#create the image search client +client = ImageSearchAPI(CognitiveServicesCredentials(subscription_key)) +# send a search query to the Bing Image Search API +image_results = client.images.search(query=search_term) +print("Searching the web for images of: {}".format(search_term)) + +# Image results +if image_results.value: + first_image_result = image_results.value[0] + print("Total number of images returned: {}".format(len(image_results.value))) + print("First image thumbnail url: {}".format(first_image_result.thumbnail_url)) + print("First image content url: {}".format(first_image_result.content_url)) +else: + print("Couldn't find image results!")