Skip to content

Instantly share code, notes, and snippets.

@quickcode00
Last active September 12, 2021 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quickcode00/3e99282ba98bc0bbb3108154e5ce1dfb to your computer and use it in GitHub Desktop.
Save quickcode00/3e99282ba98bc0bbb3108154e5ce1dfb to your computer and use it in GitHub Desktop.
def news_api_request(url: str, **kwargs) -> list:
"""
Sends GET request to News API endpoint
Inputs
----------
url: full URL for endpoint
kwargs: please refer to
News API documentations:
https://newsapi.org/docs/endpoints/
(apiKey argument is required)
Return
----------
list containing data for each article in response
"""
params = kwargs
res = requests.get(url, params=params)
articles = res.json().get('articles')
return articles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment