forked from aerodynamics-py/WEATHER_STATION_PI
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnews.py
24 lines (20 loc) · 719 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
# -*- coding:utf-8 -*-
import requests
import textwrap
class News:
def __init__(self):
pass
def update(self, api_id):
self.news_list = requests.get(
f"https://newsapi.org/v2/top-headlines?sources=google-news-fr&apiKey={api_id}").json()
return self.news_list
def selected_title(self):
list_news = []
if self.news_list["status"] == "ok":
for i in range(len(self.news_list["articles"])):
line = self.news_list["articles"][i]["title"]
line = textwrap.wrap(line, width=60)
list_news.append(line)
else:
list_news = ["Problème de chargement des news"]
return list_news