From ae46875efdd083ff695f8a936e236c5ab698bf9d Mon Sep 17 00:00:00 2001
From: Winona Azure <38537084+wiazur@users.noreply.github.com>
Date: Thu, 23 Jan 2020 21:11:23 -0800
Subject: [PATCH] Updated structure, added pretty print
---
python/Search/BingCustomSearchv7.py | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/python/Search/BingCustomSearchv7.py b/python/Search/BingCustomSearchv7.py
index 17c75bc..e7429b8 100644
--- a/python/Search/BingCustomSearchv7.py
+++ b/python/Search/BingCustomSearchv7.py
@@ -1,26 +1,32 @@
-#Copyright (c) Microsoft Corporation. All rights reserved.
-#Licensed under the MIT License.
+# Copyright (c) Microsoft Corporation. All rights reserved.
+# Licensed under the MIT License.
# You may need the below as well
-#pip install pipenv
-#pipenv install requests
+# pip install pipenv
+# pipenv install requests
#
import json
-import requests
import os
+from pprint import pprint
+import requests
-# Add your Bing Custom Search subscription key to your environment variables.
-# Your endpoint will have the form: https://.cognitiveservices.azure.com/bingcustomsearch/v7.0
+'''
+This sample uses the Bing Custom Search API to search for a query topic and get back user-controlled web page results.
+Bing Custom Search API: https://docs.microsoft.com/en-us/rest/api/cognitiveservices-bingsearch/bing-custom-search-api-v7-reference
+'''
+
+# Add your Bing Custom Search subscription key and endpoint to your environment variables.
+# Your endpoint will have the form: https://.cognitiveservices.azure.com
subscriptionKey = os.environ['BING_CUSTOM_SEARCH_SUBSCRIPTION_KEY']
endpoint = os.environ['BING_CUSTOM_SEARCH_ENDPOINT']
-customConfigId = "your-custom-config-id" #you can also use "1"
+customConfigId = os.environ["BING_CUSTOM_CONFIG"] # you can also use "1"
searchTerm = "microsoft"
#
#
# Add your Bing Custom Search endpoint to your environment variables.
-url = endpoint + "/search?q=" + searchTerm + "&customconfig=" + customConfigId
+url = endpoint + "/bingcustomsearch/v7.0/search?q=" + searchTerm + "&customconfig=" + customConfigId
#
#
r = requests.get(url, headers={'Ocp-Apim-Subscription-Key': subscriptionKey})
-print(r.text)
+pprint(json.loads(r.text))
#