-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
21 lines (19 loc) · 777 Bytes
/
api.py
File metadata and controls
21 lines (19 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import requests
API_TOKEN = "IUatdbg7HcTN2EnzCz-2mwUlp11_3Xz4YwNPqd9Lvt-oWVOj"
API_URL = "https://api.currentsapi.services/v1/latest-news"
def fetch_articles():
try:
headers = {
'Authorization': API_TOKEN
}
response = requests.get(API_URL, headers=headers)
if response.status_code == 200:
data = response.json()
articles = data.get('news', [])
return [(article['title'], article['url']) for article in articles if article.get('title') and article.get('url')]
else:
print("❌ Erreur API :", response.status_code, "-", response.text)
return []
except Exception as e:
print("❌ Erreur lors de la récupération des articles :", e)
return []