-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelenasportTest.py
45 lines (34 loc) · 1.59 KB
/
elenasportTest.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
38
39
40
41
42
43
44
45
import requests
import json
# ----------------- setup ------------------
# get auth data from auth file
with open('auth.json', 'r') as myfile:
data=myfile.read()
dataJSON = json.loads(data)
authJSON = dataJSON['elenasport']
# used for asking for access token
accessTokenURL=authJSON['endpoint']
authorization=authJSON['authorization']
content_type=authJSON['content-type']
grant_type=authJSON['grant-type']
# ask for access token
response = requests.post(accessTokenURL, headers={'Authorization':authorization, 'Content-Type':content_type}, data={'grant_type':grant_type})
data = response.json()
access_token = data['access_token'] # used for API requests
# print(access_token)
# ----------------- HTTPS requests ------------------
premLeagueID = 234
PL_21_22_seasonID = 4210
getRequestURL = 'https://football.elenasport.io/v2/seasons/4210/fixtures?&from=2021-10-12&to=2021-10-27'
getAuthorization = 'Bearer ' + access_token
response = requests.get(getRequestURL, headers={'Authorization':getAuthorization})
# currently the fixtures is not saving the referees. this prints out None for every fixture
fixtures = response.json()['data']
for fixture in fixtures:
print(fixture['referees'])
# gives fixtures for a season ID in a date range
# https://football.elenasport.io/v2/seasons/{seasonID}/fixtures?&from=YYYY-MM-DD&to=YYYY=MM-DD
# example: https://football.elenasport.io/v2/seasons/4210/fixtures?&from=2021-09-24&to=2021-09-25
# gives seasonID's for specified league ID
# https://football.elenasport.io/v2/leagues/{ID}/seasons
# example: https://football.elenasport.io/v2/leagues/234/seasons