forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_bbc_news.py
More file actions
Latest commit
17 lines (11 loc) · 556 Bytes
/
Copy pathfetch_bbc_news.py
File metadata and controls
17 lines (11 loc) · 556 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Created by sarathkaul on 12/11/19
importrequests
_NEWS_API="https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey="
deffetch_bbc_news(bbc_news_api_key: str) ->None:
# fetching a list of articles in json format
bbc_news_page=requests.get(_NEWS_API+bbc_news_api_key).json()
# each article in the list is a dict
fori, articleinenumerate(bbc_news_page["articles"], 1):
print(f"{i}.) {article['title']}")
if__name__=="__main__":
fetch_bbc_news(bbc_news_api_key="<Your BBC News API key goes here>")