-
Notifications
You must be signed in to change notification settings - Fork 6
/
newsAPI.py
28 lines (25 loc) · 964 Bytes
/
newsAPI.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
import requests # api
from bs4 import BeautifulSoup # parser html
def getNews(): # recupère les news par API et créer une liste de liste avec les informations comme le titre, le corps, la source et la date
response = requests.get('https://data.messari.io/api/v1/news').json()
articles = list()
for news in response['data']:
try:
title = BeautifulSoup(news['title'], "html.parser").get_text()
except:
title = "None"
try:
content = BeautifulSoup(news['content'], "html.parser").get_text()
except:
content = "None"
try:
source = news['references'][0]['url']
except:
news = "None"
try:
date = BeautifulSoup(news['published_at'],
"html.parser").get_text()
except:
date = "None"
articles.append([title, content, source, date])
return (articles)