[go: up one dir, main page]

Skip to content

Commit

Permalink
Update fetch_news.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SKAUL05 authored Sep 30, 2020
1 parent 06d2237 commit 5350f81
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions fetch_news.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
# Created by sarathkaul on 11/11/19

import requests

_NEWS_API = "https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey=4dbc17e007ab436fb66416009dfb59a8"


def fetch_bbc_news():
# fetching data in json format
bbc_page_fetch = requests.get(_NEWS_API).json()

# getting all articles in a string article
article = bbc_page_fetch["articles"]

# result containing all trending news
results = []
_NEWS_API = "https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey="

for a_article in article:
results.append(a_article)

for a_result in range(len(results)):
# printing all trending news
print str(a_result + 1) + ".) ", results[a_result]['title']
def fetch_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
for news, article in enumerate(bbc_news_page["articles"], 1):
print(f"{news}.) {article['title']}")


if __name__ == '__main__':
fetch_bbc_news()
if __name__ == "__main__":
fetch_bbc_news(bbc_news_api_key="<Your BBC News API key goes here>")

0 comments on commit 5350f81

Please sign in to comment.