-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexplore.py
More file actions
133 lines (119 loc) · 3.33 KB
/
explore.py
File metadata and controls
133 lines (119 loc) · 3.33 KB
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
# imports
import os
import requests
import datetime
from dotenv import load_dotenv
load_dotenv()
# request auth
API_KEY = os.getenv('API_KEY')
HEADERS = {
'x-api-key': API_KEY,
'Content-Type': 'application/json',
}
# set your subscription
# can be paid or free
MY_PLAN = 'free'
# MY_PLAN = 'paid'
API_DOMAIN = 'https://www.crunchtimeodds.com/api'
API_ENDPOINT = f'{API_DOMAIN}/v1'
if MY_PLAN == 'paid':
# privileged endpoints
API_ENDPOINT += '/adv'
# api endpoints
HEALTH_ENDPOINT = f'{API_DOMAIN}/health'
SITES_ENDPOINT = f'{API_DOMAIN}/v1/sites'
TEAMS_ENDPOINT = f'{API_DOMAIN}/v1/teams'
GAMEIDS_ENDPOINT = f'{API_ENDPOINT}/games/ids'
ML_ENDPOINT = f'{API_ENDPOINT}/ml'
OU_ENDPOINT = f'{API_ENDPOINT}/ou'
PS_ENDPOINT = f'{API_ENDPOINT}/ps'
def pretty_print_odds(j, t):
""" pretty print odds data """
print(
f"[{t.upper()} ODDS UPDATE {datetime.datetime.fromtimestamp(j['updated_at'])}] "+
f"{j['league'].upper()} | "+
f"{j['game_id']} | "+
f"{j['site_id']} | "+
f"{j['t1_id'].replace(j['league']+'-','')} {j['t1_odds']} | "+
f"{j['t2_id'].replace(j['league']+'-','')} {j['t2_odds']}"
)
def get_health():
""" health check """
resp = requests.get(HEALTH_ENDPOINT, headers=HEADERS)
if (resp.status_code == 200):
print(f"[HEALTH] {resp.json()}")
def get_teams():
""" all teams """
teams = []
resp = requests.get(TEAMS_ENDPOINT, headers=HEADERS)
if (resp.status_code == 200):
teams = [d['team_id'] for d in resp.json()]
print(f"[TEAMS] {len(teams)} teams found")
return teams
def get_sites():
""" all sites """
sites = []
resp = requests.get(SITES_ENDPOINT, headers=HEADERS)
if (resp.status_code == 200):
sites = [d['site_id'] for d in resp.json()]
print(f"[SITES] {len(sites)} sites found")
return sites
def get_game_ids(n_pages=2):
""" game ids for page(s) """
game_ids = []
for page in range(0,n_pages):
pg = page * 10
resp = requests.get(
f'{GAMEIDS_ENDPOINT}?page={pg}',
headers=HEADERS
)
if (resp.status_code == 200):
print(f"[GAME IDS] page = {page} | found {len(resp.json())} items")
game_ids.extend([d['game_id'] for d in resp.json()])
print(f"[GAME IDS] {len(game_ids)} game ids found in {n_pages} pages")
return game_ids
def print_ml_data(n_pages=1):
""" moneyline data for page(s) """
for page in range(0,n_pages):
pg = page * 10
resp = requests.get(
f'{ML_ENDPOINT}?page={pg}',
headers=HEADERS
)
if (resp.status_code == 200):
for d in resp.json():
pretty_print_odds(d, 'ml')
def print_ou_data(n_pages=1):
""" over under data for page(s) """
for page in range(0,n_pages):
pg = page * 10
resp = requests.get(
f'{OU_ENDPOINT}?page={pg}',
headers=HEADERS
)
if (resp.status_code == 200):
for d in resp.json():
pretty_print_odds(d, 'ou')
def print_ps_data(n_pages=1):
""" point spread data for page(s) """
for page in range(0,n_pages):
pg = page * 10
resp = requests.get(
f'{PS_ENDPOINT}?page={pg}',
headers=HEADERS
)
if (resp.status_code == 200):
for d in resp.json():
pretty_print_odds(d, 'ps')
if __name__ == '__main__':
get_health()
teams = get_teams()
sites = get_sites()
game_ids = get_game_ids()
print('-'*50)
print_ml_data()
print('-'*50)
print_ou_data()
print('-'*50)
print_ps_data()
print('-'*50)