-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOddsAPIScript.py
57 lines (42 loc) · 1.93 KB
/
OddsAPIScript.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
import requests
import json
# An api key is emailed to you when you sign up to a plan
# Get a free API key at https://api.the-odds-api.com/
API_KEY = 'b00dcb637ff2c90f0acf59dd1bf7fbac'
SPORT = 'americanfootball_nfl' # use the sport_key from the /sports endpoint below, or use 'upcoming' to see the next 8 games across all sports
REGIONS = 'us' # uk | us | eu | au. Multiple can be specified if comma delimited
MARKETS = 'h2h,spreads,totals' # h2h | spreads | totals. Multiple can be specified if comma delimited
ODDS_FORMAT = 'american' # decimal | american
DATE_FORMAT = 'iso' # iso | unix
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Now get a list of live & upcoming games for the sport you want, along with odds for different bookmakers
# This will deduct from the usage quota
# The usage quota cost = [number of markets specified] x [number of regions specified]
# For examples of usage quota costs, see https://the-odds-api.com/liveapi/guides/v4/#usage-quota-costs
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
odds_response = requests.get(
f'https://api.the-odds-api.com/v4/sports/{SPORT}/odds',
params={
'api_key': API_KEY,
'regions': REGIONS,
'markets': MARKETS,
'oddsFormat': ODDS_FORMAT,
'dateFormat': DATE_FORMAT,
}
)
if odds_response.status_code != 200:
print(f'Failed to get odds: status_code {odds_response.status_code}, response body {odds_response.text}')
else:
odds_json = odds_response.json()
print('Number of events:', len(odds_json))
print(odds_json)
# Check the usage quota
print('Remaining requests', odds_response.headers['x-requests-remaining'])
print('Used requests', odds_response.headers['x-requests-used'])
# Specify the filename
filename = "fanduel_data.json"
# Write JSON data to a new file
with open(filename, "w") as file:
json.dump(odds_json, file, indent=4)