-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathGetUserInputs.py
More file actions
271 lines (259 loc) · 6.21 KB
/
Copy pathGetUserInputs.py
File metadata and controls
271 lines (259 loc) · 6.21 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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
from lxml import html
import requests
def parse_input(input_team):
input_team = input_team.lower().strip()
if (
input_team == "arizona diamondbacks"
or input_team == "arizona"
or input_team == "diamondbacks"
or input_team == "ari"
):
return "Diamondbacks,ARI"
elif (
input_team == "atlanta braves"
or input_team == "atlanta"
or input_team == "braves"
or input_team == "atl"
):
return "Braves,ATL"
elif (
input_team == "baltimore"
or input_team == "orioles"
or input_team == "baltimore"
or input_team == "orioles"
or input_team == "bal"
):
return "Orioles,BAL"
elif (
input_team == "boston red sox"
or input_team == "boston"
or input_team == "red sox"
or input_team == "bos"
):
return "Red Sox,BOS"
elif input_team == "chicago cubs" or input_team == "cubs" or input_team == "chc":
return "Cubs,CHC"
elif (
input_team == "chicago white sox"
or input_team == "white sox"
or input_team == "chw"
):
return "White Sox,CHW"
elif (
input_team == "cincinnati reds"
or input_team == "cincinnati"
or input_team == "reds"
or input_team == "cin"
):
return "Reds,CIN"
elif (
input_team == "cleveland indians"
or input_team == "cleveland"
or input_team == "indians"
or input_team == "cle"
):
return "Indians,CLE"
elif (
input_team == "colorado rockies"
or input_team == "colorado"
or input_team == "rockies"
or input_team == "col"
):
return "Rockies,COL"
elif (
input_team == "detroit tigers"
or input_team == "detroit"
or input_team == "tigers"
or input_team == "det"
):
return "Tigers,DET"
elif (
input_team == "houston astros"
or input_team == "houston"
or input_team == "astros"
or input_team == "hou"
):
return "Astros,HOU"
elif (
input_team == "kansas city royals"
or input_team == "kansas city"
or input_team == "royals"
or input_team == "kcr"
):
return "Royals,KCR"
elif (
input_team == "los angeles angels"
or input_team == "anaheim angels"
or input_team == "anaheim"
or input_team == "angels"
or input_team == "ana"
):
return "Angels,ANA"
elif (
input_team == "los angeles dodgers"
or input_team == "los angeles"
or input_team == "dodgers"
or input_team == "lad"
):
return "Dodgers,LAD"
elif (
input_team == "miami marlins"
or input_team == "florida marlins"
or input_team == "miami"
or input_team == "florida"
or input_team == "marlins"
or input_team == "fla"
):
return "Marlins,FLA"
elif (
input_team == "milwaukee brewers"
or input_team == "milwaukee"
or input_team == "brewers"
or input_team == "mil"
):
return "Brewers,MIL"
elif (
input_team == "minnesota twins"
or input_team == "minnesota"
or input_team == "twins"
or input_team == "min"
):
return "Twins,MIN"
elif input_team == "new york mets" or input_team == "mets" or input_team == "nym":
return "Mets,NYM"
elif (
input_team == "new york yankees"
or input_team == "yankees"
or input_team == "nyy"
):
return "Yankees,NYY"
elif (
input_team == "oakland athletics"
or input_team == "oakland"
or input_team == "athletics"
or input_team == "as"
or input_team == "a's"
or input_team == "oak"
):
return "Athletics,OAK"
elif (
input_team == "philadelphia phillies"
or input_team == "philadelphia"
or input_team == "phillies"
or input_team == "phi"
):
return "Phillies,PHI"
elif (
input_team == "pittsburgh pirates"
or input_team == "pittsburgh"
or input_team == "pirates"
or input_team == "pit"
):
return "Pirates,PIT"
elif (
input_team == "san diego padres"
or input_team == "san diego"
or input_team == "padres"
or input_team == "sdp"
):
return "Padres,SDP"
elif (
input_team == "san francisco giants"
or input_team == "san francisco"
or input_team == "giants"
or input_team == "sfg"
):
return "Giants,SFG"
elif (
input_team == "seattle mariners"
or input_team == "seattle"
or input_team == "mariners"
or input_team == "sea"
):
return "Mariners,SEA"
elif (
input_team == "st louis cardinals"
or input_team == "st. louis cardinals"
or input_team == "st louis"
or input_team == "st. louis"
or input_team == "cardinals"
or input_team == "stl"
):
return "Cardinals,STL"
elif (
input_team == "tampa bay rays"
or input_team == "tampa bay"
or input_team == "rays"
or input_team == "tampa bay devil rays"
or input_team == "devil rays"
or input_team == "tbd"
):
return "Rays,TBD"
elif (
input_team == "texas rangers"
or input_team == "texas"
or input_team == "rangers"
or input_team == "tex"
):
return "Rangers,TEX"
elif (
input_team == "toronto blue jays"
or input_team == "toronto"
or input_team == "blue jays"
or input_team == "tor"
):
return "Blue Jays,TOR"
elif (
input_team == "washington nationals"
or input_team == "washington"
or input_team == "nationals"
or input_team == "wsn"
):
return "Nationals,WSN"
else:
return "invalid"
def GetUserInputs():
home_team_error = True
while home_team_error == True:
team = input("Enter the name of the home team: ")
if parse_input(team) == "invalid":
print("Invalid team.")
continue
else:
homeTeam = parse_input(team).split(",")[0]
homeAbbr = parse_input(team).split(",")[1]
home_team_error = False
home_year_error = True
while home_year_error == True:
homeYear = input("Enter year: ")
home_page = requests.get( "https://www.baseball-reference.com/teams/"
+ homeAbbr + "/" + homeYear + ".shtml")
if str(home_page) != "<Response [200]>":
print("Invalid year.")
continue
else:
home_year_error = False
away_team_error = True
while away_team_error == True:
awayTeam = input("Enter the name of the away team: ")
if parse_input(awayTeam) == "invalid":
print("Invalid team.")
continue
else:
awayTeam = parse_input(awayTeam).split(",")[0]
awayAbbr = parse_input(awayTeam).split(",")[1]
away_team_error = False
away_year_error = True
while away_year_error == True:
awayYear = input("Enter year: ")
away_page = requests.get(
"https://www.baseball-reference.com/teams/" + awayAbbr
+ "/" + awayYear + ".shtml"
)
if str(away_page) != "<Response [200]>":
print("Invalid year.")
continue
else:
away_year_error = False
inputsArray = [homeTeam, awayTeam, homeAbbr, awayAbbr, homeYear, awayYear]
return inputsArray