-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfootball_api.py
37 lines (30 loc) · 895 Bytes
/
football_api.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
33
34
35
36
37
import os
import httpx
from dotenv import load_dotenv
season = 2023
league_id = 51
load_dotenv()
# Create a client session for HTTP requests
client = httpx.Client(base_url='https://api-football-v1.p.rapidapi.com/v3/')
def get_fixtures():
headers = {
'x-rapidapi-key': os.environ['API_FOOTBALL_KEY'],
'x-rapidapi-host': 'api-football-v1.p.rapidapi.com',
}
params = {
'league': league_id,
'season': season,
}
response = client.get('fixtures', headers=headers, params=params)
return response.json()
def get_standings():
headers = {
'x-rapidapi-key': os.environ['API_FOOTBALL_KEY'],
'x-rapidapi-host': 'api-football-v1.p.rapidapi.com',
}
params = {
'league': league_id,
'season': season,
}
response = client.get('standings', headers=headers, params=params)
return response.json()