-
-
Notifications
You must be signed in to change notification settings - Fork 812
/
getters.py
134 lines (120 loc) · 4.13 KB
/
getters.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import requests
import json
import time
def get_data():
""" Retrieve the fpl player data from the hard-coded url
"""
response = requests.get("https://fantasy.premierleague.com/api/bootstrap-static/")
if response.status_code != 200:
raise Exception("Response was code " + str(response.status_code))
responseStr = response.text
data = json.loads(responseStr)
return data
def get_individual_player_data(player_id):
""" Retrieve the player-specific detailed data
Args:
player_id (int): ID of the player whose data is to be retrieved
"""
base_url = "https://fantasy.premierleague.com/api/element-summary/"
full_url = base_url + str(player_id) + "/"
response = ''
while response == '':
try:
response = requests.get(full_url)
except:
time.sleep(5)
if response.status_code != 200:
raise Exception("Response was code " + str(response.status_code))
data = json.loads(response.text)
return data
def get_entry_data(entry_id):
""" Retrieve the summary/history data for a specific entry/team
Args:
entry_id (int) : ID of the team whose data is to be retrieved
"""
base_url = "https://fantasy.premierleague.com/api/entry/"
full_url = base_url + str(entry_id) + "/history/"
response = ''
while response == '':
try:
response = requests.get(full_url)
except:
time.sleep(5)
if response.status_code != 200:
raise Exception("Response was code " + str(response.status_code))
data = json.loads(response.text)
return data
def get_entry_personal_data(entry_id):
""" Retrieve the summary/history data for a specific entry/team
Args:
entry_id (int) : ID of the team whose data is to be retrieved
"""
base_url = "https://fantasy.premierleague.com/api/entry/"
full_url = base_url + str(entry_id) + "/"
response = ''
while response == '':
try:
response = requests.get(full_url)
except:
time.sleep(5)
if response.status_code != 200:
raise Exception("Response was code " + str(response.status_code))
data = json.loads(response.text)
return data
def get_entry_gws_data(entry_id,num_gws,start_gw=1):
""" Retrieve the gw-by-gw data for a specific entry/team
Args:
entry_id (int) : ID of the team whose data is to be retrieved
"""
base_url = "https://fantasy.premierleague.com/api/entry/"
gw_data = []
for i in range(start_gw, num_gws+1):
full_url = base_url + str(entry_id) + "/event/" + str(i) + "/picks/"
response = ''
while response == '':
try:
response = requests.get(full_url)
except:
time.sleep(5)
if response.status_code != 200:
raise Exception("Response was code " + str(response.status_code))
data = json.loads(response.text)
gw_data += [data]
return gw_data
def get_entry_transfers_data(entry_id):
""" Retrieve the transfer data for a specific entry/team
Args:
entry_id (int) : ID of the team whose data is to be retrieved
"""
base_url = "https://fantasy.premierleague.com/api/entry/"
full_url = base_url + str(entry_id) + "/transfers/"
response = ''
while response == '':
try:
response = requests.get(full_url)
except:
time.sleep(5)
if response.status_code != 200:
raise Exception("Response was code " + str(response.status_code))
data = json.loads(response.text)
return data
def get_fixtures_data():
""" Retrieve the fixtures data for the season
"""
url = "https://fantasy.premierleague.com/api/fixtures/"
response = ''
while response == '':
try:
response = requests.get(url)
except:
time.sleep(5)
if response.status_code != 200:
raise Exception("Response was code " + str(response.status_code))
data = json.loads(response.text)
return data
def main():
data = get_data()
with open('raw.json', 'w') as outf:
json.dump(data, outf)
if __name__ == '__main__':
main()