-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
170 lines (155 loc) · 5.94 KB
/
main.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import json
import requests
from twilio.rest import Client
import datetime
import os
# 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/
ODDS_API_KEY = os.environ.get("ODDS_API_KEY")
TWILIO_ACCOUNT_SID = os.environ.get("TWILIO_ACCOUNT_SID")
TWILIO_AUTH_TOKEN = os.environ.get("TWILIO_AUTH_TOKEN")
MY_SMS_NUMBER = os.environ.get("MY_SMS_NUMBER")
TWILIO_SMS_NUMBER = os.environ.get("TWILIO_SMS_NUMBER")
def team_name_to_abbr(full_name):
if full_name == "Kansas City Chiefs":
return "KC"
if full_name == "Los Angeles Chargers":
return "LAC"
if full_name == "Baltimore Ravens":
return "BAL"
if full_name == "Miami Dolphins":
return "MIA"
if full_name == "New York Giants":
return "NYG"
if full_name == "Carolina Panthers":
return "CAR"
if full_name == "Cleveland Browns":
return "CLE"
if full_name == "New York Jets":
return "NYJ"
if full_name == "Detroit Lions":
return "DET"
if full_name == "Washington Commanders":
return "WAS"
if full_name == "Jacksonville Jaguars":
return "JAC"
if full_name == "Indianapolis Colts":
return "IND"
if full_name == "Pittsburgh Steelers":
return "PIT"
if full_name == "New England Patriots":
return "NE"
if full_name == "New Orleans Saints":
return "NO"
if full_name == "Tampa Bay Buccaneers":
return "TB"
if full_name == "Los Angeles Rams":
return "LAR"
if full_name == "Atlanta Falcons":
return "ATL"
if full_name == "San Francisco 49ers":
return "SF"
if full_name == "Seattle Seahawks":
return "SEA"
if full_name == "Las Vegas Raiders":
return "LV"
if full_name == "Arizona Cardinals":
return "ARI"
if full_name == "Dallas Cowboys":
return "DAL"
if full_name == "Cincinnati Bengals":
return "CIN"
if full_name == "Denver Broncos":
return "DEN"
if full_name == "Houston Texans":
return "HOU"
if full_name == "Green Bay Packers":
return "GB"
if full_name == "Chicago Bears":
return "CHI"
if full_name == "Buffalo Bills":
return "BUF"
if full_name == "Tennessee Titans":
return "TEN"
if full_name == "Philadelphia Eagles":
return "PHI"
if full_name == "Minnesota Vikings":
return "MIN"
return full_name
def favor_bird_team(name):
if name == "BAL" or name == "ATL" or name == "ARI" or name == "PHI":
return -3.5
else:
return 0.0
def favor_graces_teams(name):
if name == "SEA":
return -7.5
if name == "MIN":
return -6.0
elif name == "PIT" or name == "TEN" or name == "LAC":
return -5.0
elif name == "NO":
return -3.5
elif name == "MIA":
return -1.5
else:
return 0.0
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# 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
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
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 = 'spreads' # h2h | spreads | totals. Multiple can be specified if comma delimited
ODDS_FORMAT = 'decimal' # decimal | american
DATE_FORMAT = 'iso' # iso | unix
odds_response = requests.get(f'https://api.the-odds-api.com/v4/sports/{SPORT}/odds', params={
'api_key': ODDS_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:
print("successfully got odds data from sports api")
odds = odds_response.json()
with open("odds.json", "w") as write_file:
json.dump(odds, write_file, indent=4)
# Check the usage quota
print('Remaining requests\n', odds_response.headers['x-requests-remaining'])
matchups = ""
for game in range(0, len(odds)):
home = team_name_to_abbr(odds[game]['home_team'])
away = team_name_to_abbr(odds[game]['away_team'])
avg_spread = 0
commence = datetime.datetime.strptime(odds[game]["commence_time"], '%Y-%m-%dT%H:%M:%SZ') - datetime.timedelta(
hours=4)
current = datetime.datetime.now()
if current < commence:
for bmkr in range (0, len(odds[game]['bookmakers'])):
# check the team names to determine home team index
if home == team_name_to_abbr(odds[game]['bookmakers'][bmkr]['markets'][0]['outcomes'][0]['name']):
index = 0
else:
index = 1
avg_spread += odds[game]['bookmakers'][bmkr]['markets'][0]['outcomes'][index]['point']
avg_spread = avg_spread / len(odds[game]['bookmakers'])
bt_spread = avg_spread + favor_bird_team(home) - favor_bird_team(away)
bt_grace_spread = bt_spread + favor_graces_teams(home) - favor_graces_teams(away)
if bt_grace_spread < 0.0:
pick = home
else:
pick = away
matchups = matchups + away + " @ " + home + " ({:.2f})".format(avg_spread) + " => " + pick + "\n"
print(away, "@", home, "({:.2f})".format(avg_spread), "=>", pick)
client = Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
message = client.messages.create(
to=MY_SMS_NUMBER,
from_=TWILIO_SMS_NUMBER,
body=matchups)