nesticot commited on
Commit
528f65d
·
verified ·
1 Parent(s): 3b489d1

Update functions/PitchPlotFunctions.py

Browse files
Files changed (1) hide show
  1. 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
- if sport_id == 1:
162
- url = f'https://img.mlbstatic.com/mlb-photos/image/'\
163
- f'upload/d_people:generic:headshot:67:current.png'\
164
- f'/w_640,q_auto:best/v1/people/{pitcher_id}/headshot/silo/current.png'
165
- else:
166
- url = f'https://img.mlbstatic.com/mlb-photos/image/upload/c_fill,g_auto/w_640/v1/people/{pitcher_id}/headshot/milb/current.png'
167
-
168
- # Send a GET request to the URL
169
- response = requests.get(url)
170
- # Open the image from the response content
171
- img = Image.open(BytesIO(response.content))
172
- # Display the image on the axis
173
- ax.set_xlim(0, 1)
174
- ax.set_ylim(0, 1)
175
- if sport_id == 1:
176
- ax.imshow(img, extent=[0, 1, 0, 1], origin='upper')
177
- else:
178
- ax.imshow(img, extent=[1/6, 5/6, 0, 1], origin='upper')
 
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