Skip to content

Commit 1cd153f

Browse files
authored
Merge pull request #30 from iscai-msft/news_search
updated news search samples
2 parents 4250fb7 + 4a75c2d commit 1cd153f

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ azure-cognitiveservices-language-textanalytics
55
azure-cognitiveservices-search-autosuggest>=1.0
66
azure-cognitiveservices-search-customsearch
77
azure-cognitiveservices-search-entitysearch
8-
azure-cognitiveservices-search-imagesearch>=1.0
9-
azure-cognitiveservices-search-newssearch
8+
azure-cognitiveservices-search-imagesearch
9+
azure-cognitiveservices-search-newssearch>=2.0.0
1010
azure-cognitiveservices-search-videosearch
1111
azure-cognitiveservices-search-visualsearch>=0.2.0 # sample won't work with previous versions
1212
azure-cognitiveservices-search-websearch

samples/search/news_search_samples.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from azure.cognitiveservices.search.newssearch import NewsSearchAPI
1+
from azure.cognitiveservices.search.newssearch import NewsSearchClient
22
from msrest.authentication import CognitiveServicesCredentials
33

44
# Add your Bing Search V7 subscription key to your environment variables.
@@ -10,7 +10,10 @@ def news_search(subscription_key):
1010
1111
This will search news for (Quantum Computing) with market and count parameters then verify number of results and print out totalEstimatedMatches, name, url, description, published time and name of provider of the first news result
1212
"""
13-
client = NewsSearchAPI(CognitiveServicesCredentials(subscription_key))
13+
client = NewsSearchClient(
14+
endpoint="https://api.cognitive.microsoft.com",
15+
credentials=CognitiveServicesCredentials(subscription_key)
16+
)
1417

1518
try:
1619
news_result = client.news.search(
@@ -42,7 +45,10 @@ def news_search_with_filtering(subscription_key):
4245
4346
This will search most recent news for (Artificial Intelligence) with freshness and sortBy parameters then verify number of results and print out totalEstimatedMatches, name, url, description, published time and name of provider of the first news result.
4447
"""
45-
client = NewsSearchAPI(CognitiveServicesCredentials(subscription_key))
48+
client = NewsSearchClient(
49+
endpoint="https://api.cognitive.microsoft.com",
50+
credentials=CognitiveServicesCredentials(subscription_key)
51+
)
4652

4753
try:
4854
news_result = client.news.search(
@@ -76,7 +82,10 @@ def news_category(subscription_key):
7682
7783
This will search category news for movie and TV entertainment with safe search then verify number of results and print out category, name, url, description, published time and name of provider of the first news result.
7884
"""
79-
client = NewsSearchAPI(CognitiveServicesCredentials(subscription_key))
85+
client = NewsSearchClient(
86+
endpoint="https://api.cognitive.microsoft.com",
87+
credentials=CognitiveServicesCredentials(subscription_key)
88+
)
8089

8190
try:
8291
news_result = client.news.category(
@@ -110,7 +119,10 @@ def news_trending(subscription_key):
110119
111120
This will search news trending topics in Bing then verify number of results and print out name, text of query, webSearchUrl, newsSearchUrl and image Url of the first news result.
112121
"""
113-
client = NewsSearchAPI(CognitiveServicesCredentials(subscription_key))
122+
client = NewsSearchClient(
123+
endpoint="https://api.cognitive.microsoft.com",
124+
credentials=CognitiveServicesCredentials(subscription_key)
125+
)
114126

115127
try:
116128
trending_topics = client.news.trending(market="en-us")

0 commit comments

Comments
 (0)