Skip to content

Commit 5298ba5

Browse files
committed
updated news search samples for latest release
1 parent 81b6423 commit 5298ba5

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,6 @@ ENV/
9999

100100
# mypy
101101
.mypy_cache/
102+
103+
# idea
104+
.idea/

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ azure-cognitiveservices-search-autosuggest
55
azure-cognitiveservices-search-customsearch
66
azure-cognitiveservices-search-entitysearch
77
azure-cognitiveservices-search-imagesearch
8-
azure-cognitiveservices-search-newssearch
8+
azure-cognitiveservices-search-newssearch>=2.0.0
99
azure-cognitiveservices-search-videosearch
1010
azure-cognitiveservices-search-visualsearch
1111
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
SUBSCRIPTION_KEY_ENV_NAME = "NEWSSEARCH_SUBSCRIPTION_KEY"
@@ -8,7 +8,10 @@ def news_search(subscription_key):
88
99
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
1010
"""
11-
client = NewsSearchAPI(CognitiveServicesCredentials(subscription_key))
11+
client = NewsSearchClient(
12+
endpoint="https://api.cognitive.microsoft.com",
13+
credentials=CognitiveServicesCredentials(subscription_key)
14+
)
1215

1316
try:
1417
news_result = client.news.search(query="Quantum Computing", market="en-us", count=10)
@@ -35,7 +38,10 @@ def news_search_with_filtering(subscription_key):
3538
3639
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.
3740
"""
38-
client = NewsSearchAPI(CognitiveServicesCredentials(subscription_key))
41+
client = NewsSearchClient(
42+
endpoint="https://api.cognitive.microsoft.com",
43+
credentials=CognitiveServicesCredentials(subscription_key)
44+
)
3945

4046
try:
4147
news_result = client.news.search(
@@ -66,7 +72,10 @@ def news_category(subscription_key):
6672
6773
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.
6874
"""
69-
client = NewsSearchAPI(CognitiveServicesCredentials(subscription_key))
75+
client = NewsSearchClient(
76+
endpoint="https://api.cognitive.microsoft.com",
77+
credentials=CognitiveServicesCredentials(subscription_key)
78+
)
7079

7180
try:
7281
news_result = client.news.category(
@@ -97,7 +106,10 @@ def news_trending(subscription_key):
97106
98107
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.
99108
"""
100-
client = NewsSearchAPI(CognitiveServicesCredentials(subscription_key))
109+
client = NewsSearchClient(
110+
endpoint="https://api.cognitive.microsoft.com",
111+
credentials=CognitiveServicesCredentials(subscription_key)
112+
)
101113

102114
try:
103115
trending_topics = client.news.trending(market="en-us")

0 commit comments

Comments
 (0)