Skip to content

Commit a5ad7d8

Browse files
authored
Merge pull request #1 from FGhavamian/add_searchin
add searchIn param to payload
2 parents 56fc873 + 2a4503d commit a5ad7d8

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

newsapi/newsapi_client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def get_everything( # noqa: C901
178178
self,
179179
q=None,
180180
qintitle=None,
181+
searchIn=None,
181182
sources=None,
182183
domains=None,
183184
exclude_domains=None,
@@ -200,6 +201,10 @@ def get_everything( # noqa: C901
200201
`documentation <https://newsapi.org/docs/endpoints/everything>`_ for search syntax and examples.
201202
:type q: str or None
202203
204+
:param searchIn: The fields to restrict your q search to. Should be either title, content, or description. See the official News API
205+
`documentation <https://newsapi.org/docs/endpoints/everything>`_ for search syntax and examples.
206+
:type q: str or None
207+
203208
:param sources: A comma-seperated string of identifiers for the news sources or blogs you want headlines from.
204209
Use :meth:`NewsApiClient.get_sources` to locate these programmatically, or look at the
205210
`sources index <https://newsapi.org/sources>`_.
@@ -262,6 +267,16 @@ def get_everything( # noqa: C901
262267
else:
263268
raise TypeError("keyword/phrase qintitle param should be of type str")
264269

270+
# SearchIn
271+
if searchIn is not None:
272+
if is_valid_string(searchIn):
273+
if searchIn in ["title", "content", "description"]:
274+
payload["searchIn"] = searchIn
275+
else:
276+
raise ValueError(
277+
f"searchIn param should be either title, content, or description. {searchIn} is given. "
278+
)
279+
265280
# Sources
266281
if sources is not None:
267282
if is_valid_string(sources):

tests/test_newsapi_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ def test_api_get_everything(self):
146146
with self.assertRaises(ValueError):
147147
self.api.get_everything(page=page)
148148

149+
# Raises a ValueError if searchIn param is not equal to either title, description, or content
150+
searchIn = "date"
151+
with self.assertRaises(ValueError):
152+
self.api.get_everything(searchIn=searchIn)
153+
149154
def test_api_get_sources(self):
150155
# Raise TypeError if language param is not of type str
151156
language = 0

0 commit comments

Comments
 (0)