Skip to content

Commit 5e4fc44

Browse files
SKAUL05stokhos
authored andcommitted
Python Program that fetches top trending news (TheAlgorithms#1559)
* Python Program that fetches top trending news * Python Program that fetches top trending news * Revisions in Fetch BBC News
1 parent 7bb8ba3 commit 5e4fc44

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: web_programming/fetch_bbc_news.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Created by sarathkaul on 12/11/19
2+
3+
import requests
4+
5+
# Enter Your API Key in following URL
6+
_NEWS_API = "https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey="
7+
8+
9+
def fetch_bbc_news(bbc_news_api_key: str) -> None:
10+
# fetching a list of articles in json format
11+
bbc_news_page = requests.get(_NEWS_API + bbc_news_api_key).json()
12+
# each article in the list is a dict
13+
for i, article in enumerate(bbc_news_page["articles"], 1):
14+
print(f"{i}.) {article['title']}")
15+
16+
17+
if __name__ == '__main__':
18+
fetch_bbc_news(bbc_news_api_key="<Your BBC News API key goes here>")

0 commit comments

Comments
 (0)