Skip to content

Commit 9e55789

Browse files
MichaelBalazsmattlisiv
authored andcommitted
Added qintitle support (#58)
* Added support for qintitle parameter. * Minor fix to comment.
1 parent 7686104 commit 9e55789

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

newsapi/newsapi_client.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, api_key, session=None):
3030
self.request_method = session
3131

3232
def get_top_headlines( # noqa: C901
33-
self, q=None, sources=None, language="en", country=None, category=None, page_size=None, page=None
33+
self, q=None, qintitle=None, sources=None, language="en", country=None, category=None, page_size=None, page=None
3434
):
3535
"""Call the `/top-headlines` endpoint.
3636
@@ -44,6 +44,10 @@ def get_top_headlines( # noqa: C901
4444
`documentation <https://newsapi.org/docs/endpoints/everything>`_ for search syntax and examples.
4545
:type q: str or None
4646
47+
:param qintitle: Keywords or a phrase to search for in the article title and body. See the official News API
48+
`documentation <https://newsapi.org/docs/endpoints/everything>`_ for search syntax and examples.
49+
:type q: str or None
50+
4751
:param sources: A comma-seperated string of identifiers for the news sources or blogs you want headlines from.
4852
Use :meth:`NewsApiClient.get_sources` to locate these programmatically, or look at the
4953
`sources index <https://newsapi.org/sources>`_. **Note**: you can't mix this param with the
@@ -89,6 +93,13 @@ def get_top_headlines( # noqa: C901
8993
else:
9094
raise TypeError("keyword/phrase q param should be of type str")
9195

96+
# Keyword/Phrase in Title
97+
if qintitle is not None:
98+
if is_valid_string(qintitle):
99+
payload["qintitle"] = qintitle
100+
else:
101+
raise TypeError("keyword/phrase qintitle param should be of type str")
102+
92103
# Sources
93104
if (sources is not None) and ((country is not None) or (category is not None)):
94105
raise ValueError("cannot mix country/category param with sources param.")
@@ -162,6 +173,7 @@ def get_top_headlines( # noqa: C901
162173
def get_everything( # noqa: C901
163174
self,
164175
q=None,
176+
qintitle=None,
165177
sources=None,
166178
domains=None,
167179
exclude_domains=None,
@@ -180,6 +192,10 @@ def get_everything( # noqa: C901
180192
`documentation <https://newsapi.org/docs/endpoints/everything>`_ for search syntax and examples.
181193
:type q: str or None
182194
195+
:param qintitle: Keywords or a phrase to search for in the article title and body. See the official News API
196+
`documentation <https://newsapi.org/docs/endpoints/everything>`_ for search syntax and examples.
197+
:type q: str or None
198+
183199
:param sources: A comma-seperated string of identifiers for the news sources or blogs you want headlines from.
184200
Use :meth:`NewsApiClient.get_sources` to locate these programmatically, or look at the
185201
`sources index <https://newsapi.org/sources>`_.
@@ -227,6 +243,13 @@ def get_everything( # noqa: C901
227243
else:
228244
raise TypeError("keyword/phrase q param should be of type str")
229245

246+
# Keyword/Phrase in Title
247+
if qintitle is not None:
248+
if is_valid_string(qintitle):
249+
payload["qintitle"] = qintitle
250+
else:
251+
raise TypeError("keyword/phrase qintitle param should be of type str")
252+
230253
# Sources
231254
if sources is not None:
232255
if is_valid_string(sources):

0 commit comments

Comments
 (0)