-
Notifications
You must be signed in to change notification settings - Fork 0
/
news.py
32 lines (23 loc) · 1016 Bytes
/
news.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from passwords import api_key
from newsapi import NewsApiClient
from datetime import datetime, timedelta, date
import country_converter as coco
from passwords import api_key
class Scraper:
def __init__(self):
self.time_start = str(date.today() - timedelta(days=7))
self.newsapi = NewsApiClient(api_key=api_key) # api_key is in passwords.py file
def get_global_news(self):
data = self.newsapi.get_top_headlines(q='covid-19', language='en')
articles = data['articles']
global_news = {}
for article in articles:
global_news.update({article['author'] : article['description']})
return global_news
def get_country_news(self, country):
data = self.newsapi.get_top_headlines(q='covid-19', country=country)
articles = data['articles']
country_news = {}
for article in articles:
country_news.update({article['author'] : article['description']})
return country_news