Update functions/PitchPlotFunctions.py
Browse files- functions/PitchPlotFunctions.py +21 -18
functions/PitchPlotFunctions.py
CHANGED
|
@@ -158,25 +158,28 @@ class PitchPlotFunctions:
|
|
| 158 |
sport_id (int): The sport ID to determine the URL format.
|
| 159 |
"""
|
| 160 |
# Construct the URL for the player's headshot image
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
|
|
|
| 179 |
# Turn off the axis
|
|
|
|
|
|
|
| 180 |
ax.axis('off')
|
| 181 |
|
| 182 |
# Function to display player bio information on the given axis
|
|
|
|
| 158 |
sport_id (int): The sport ID to determine the URL format.
|
| 159 |
"""
|
| 160 |
# Construct the URL for the player's headshot image
|
| 161 |
+
try:
|
| 162 |
+
if sport_id == 1:
|
| 163 |
+
url = f'https://img.mlbstatic.com/mlb-photos/image/'\
|
| 164 |
+
f'upload/d_people:generic:headshot:67:current.png'\
|
| 165 |
+
f'/w_640,q_auto:best/v1/people/{pitcher_id}/headshot/silo/current.png'
|
| 166 |
+
else:
|
| 167 |
+
url = f'https://img.mlbstatic.com/mlb-photos/image/upload/c_fill,g_auto/w_640/v1/people/{pitcher_id}/headshot/milb/current.png'
|
| 168 |
+
|
| 169 |
+
# Send a GET request to the URL
|
| 170 |
+
response = requests.get(url)
|
| 171 |
+
# Open the image from the response content
|
| 172 |
+
img = Image.open(BytesIO(response.content))
|
| 173 |
+
# Display the image on the axis
|
| 174 |
+
ax.set_xlim(0, 1)
|
| 175 |
+
ax.set_ylim(0, 1)
|
| 176 |
+
if sport_id == 1:
|
| 177 |
+
ax.imshow(img, extent=[0, 1, 0, 1], origin='upper')
|
| 178 |
+
else:
|
| 179 |
+
ax.imshow(img, extent=[1/6, 5/6, 0, 1], origin='upper')
|
| 180 |
# Turn off the axis
|
| 181 |
+
except PIL.UnidentifiedImageError:
|
| 182 |
+
print('NA')
|
| 183 |
ax.axis('off')
|
| 184 |
|
| 185 |
# Function to display player bio information on the given axis
|