Skip to content

Commit 8a9ccfa

Browse files
authored
Merge pull request #10 from 404-brain/patch-2
Docstrings for client endpoints
2 parents 013419b + f21da8a commit 8a9ccfa

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

newsapi/newsapi_client.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,33 @@ def __init__(self, api_key, api_url='https://newsapi.org/v2/'):
1010

1111
def get_top_headlines(self, q=None, sources=None, language=None, country=None, category=None, page_size=None,
1212
page=None):
13+
"""
14+
Returns live top and breaking headlines for a country, specific category in a country, single source, or multiple sources..
15+
16+
Optional parameters:
17+
(str) q - return headlines w/ specified coin! Valid values are:
18+
'bitcoin', 'etheremum', 'ripple', 'bitcoin cash', etc.
19+
20+
(str) sources - return headlines of news sources! some Valid values are:
21+
'bbc-news', 'the-verge', 'abc-news', 'crypto coins news',
22+
'ary news','associated press','wired','aftenposten','australian financial review','axios',
23+
'bbc news','bild','blasting news','bloomberg','business insider','engadget','google news',
24+
'hacker news','info money,'recode','techcrunch','techradar','the next web','the verge' etc.
25+
26+
(str) language - The 2-letter ISO-639-1 code of the language you want to get headlines for. Valid values are:
27+
'ar','de','en','es','fr','he','it','nl','no','pt','ru','se','ud','zh'
28+
29+
(str) country - The 2-letter ISO 3166-1 code of the country you want to get headlines! Valid values are:
30+
'ae','ar','at','au','be','bg','br','ca','ch','cn','co','cu','cz','de','eg','fr','gb','gr', 'hk','hu','id','ie','il','in','it','jp','kr','lt','lv','ma','mx','my','ng','nl','no','nz','ph' 'pl','pt','ro','rs','ru','sa','se','sg','si','sk','th','tr','tw','ua','us'
31+
32+
(str) category - The category you want to get headlines for! Valid values are:
33+
'business','entertainment','general','health','science','sports','technology'
34+
35+
(int) page_size - The number of results to return per page (request). 20 is the default, 100 is the maximum.
36+
37+
(int) page - Use this to page through the results if the total results found is greater than the page size.
38+
"""
39+
1340
# Define Payload
1441
payload = {}
1542
payload['q'] = q
@@ -26,6 +53,34 @@ def get_top_headlines(self, q=None, sources=None, language=None, country=None, c
2653

2754
def get_everything(self, q=None, sources=None, domains=None, from_parameter=None, to=None, language=None,
2855
sort_by=None, page=None, page_size=None):
56+
"""
57+
Search through millions of articles from over 5,000 large and small news sources and blogs.
58+
59+
Optional parameters:
60+
(str) q - return headlines w/ specified coin! Valid values are:
61+
'bitcoin', 'etheremum', 'ripple', 'bitcoin cash', etc.
62+
63+
(str) sources - return headlines of news sources! some Valid values are:
64+
'bbc-news', 'the-verge', 'abc-news', 'crypto coins news',
65+
'ary news','associated press','wired','aftenposten','australian financial review','axios',
66+
'bbc news','bild','blasting news','bloomberg','business insider','engadget','google news',
67+
'hacker news','info money,'recode','techcrunch','techradar','the next web','the verge' etc.
68+
69+
(str) domains - A comma-seperated string of domains (eg bbc.co.uk, techcrunch.com, engadget.com) to restrict the search to.
70+
(str) from_parameter - A date and optional time for the oldest article allowed.(e.g. 2018-03-05 or 2018-03-05T03:46:15)
71+
72+
(str) to - A date and optional time for the newest article allowed.
73+
74+
(str) language - The 2-letter ISO-639-1 code of the language you want to get headlines for. Valid values are:
75+
'ar','de','en','es','fr','he','it','nl','no','pt','ru','se','ud','zh'
76+
77+
(str) sort_by - The order to sort the articles in. Valid values are: 'relevancy','popularity','publishedAt',
78+
'relevancy'
79+
80+
(int) page_size - The number of results to return per page (request). 20 is the default, 100 is the maximum.
81+
(int) page - Use this to page through the results if the total results found is greater than the page size.
82+
"""
83+
2984
# Define Payload
3085
payload = {}
3186
payload['q'] = q
@@ -43,6 +98,23 @@ def get_everything(self, q=None, sources=None, domains=None, from_parameter=None
4398
return r.json()
4499

45100
def get_sources(self, category=None, language=None, country=None):
101+
102+
"""
103+
Returns the subset of news publishers that top headlines...
104+
105+
Optional parameters:
106+
107+
(str) language - The 2-letter ISO-639-1 code of the language you want to get headlines for. Valid values are:
108+
'ar','de','en','es','fr','he','it','nl','no','pt','ru','se','ud','zh'
109+
110+
(str) country - The 2-letter ISO 3166-1 code of the country you want to get headlines! Valid values are:
111+
'ae','ar','at','au','be','bg','br','ca','ch','cn','co','cu','cz','de','eg','fr','gb','gr', 'hk','hu','id','ie','il','in','it','jp','kr','lt','lv','ma','mx','my','ng','nl','no','nz','ph' 'pl','pt','ro','rs','ru','sa','se','sg','si','sk','th','tr','tw','ua','us'
112+
113+
(str) category - The category you want to get headlines for! Valid values are:
114+
'business','entertainment','general','health','science','sports','technology'
115+
116+
"""
117+
46118
# Define Payload
47119
payload = {}
48120
payload['category'] = category

0 commit comments

Comments
 (0)