nesticot commited on
Commit
606c282
·
verified ·
1 Parent(s): 6afe0d4

Update api_scraper.py

Browse files
Files changed (1) hide show
  1. api_scraper.py +8 -11
api_scraper.py CHANGED
@@ -139,10 +139,9 @@ class MLB_Scrape:
139
 
140
  return game_df
141
 
142
-
143
  def get_data(self, game_list_input: list):
144
  """
145
- Retrieves live game data for a list of game IDs in parallel.
146
 
147
  Parameters:
148
  - game_list_input (list): A list of game IDs for which to retrieve live data.
@@ -153,18 +152,16 @@ class MLB_Scrape:
153
  data_total = []
154
  print('This May Take a While. Progress Bar shows Completion of Data Retrieval.')
155
 
156
- def fetch_data(game_id):
157
- r = requests.get(f'https://statsapi.mlb.com/api/v1.1/game/{game_id}/feed/live')
158
- return r.json()
159
-
160
- with ThreadPoolExecutor() as executor:
161
- futures = {executor.submit(fetch_data, game_id): game_id for game_id in game_list_input}
162
- for future in tqdm(as_completed(futures), total=len(futures), desc="Processing", unit="iteration"):
163
- data_total.append(future.result())
164
- time.sleep(0.1)
165
 
166
  return data_total
167
 
 
168
  def get_data_df(self, data_list):
169
  """
170
  Converts a list of game data JSON objects into a Polars DataFrame.
 
139
 
140
  return game_df
141
 
 
142
  def get_data(self, game_list_input: list):
143
  """
144
+ Retrieves live game data for a list of game IDs.
145
 
146
  Parameters:
147
  - game_list_input (list): A list of game IDs for which to retrieve live data.
 
152
  data_total = []
153
  print('This May Take a While. Progress Bar shows Completion of Data Retrieval.')
154
 
155
+ # Iterate over the list of game IDs with a progress bar
156
+ for i in tqdm(range(len(game_list_input)), desc="Processing", unit="iteration"):
157
+ # Make a GET request to the MLB API for each game ID
158
+ r = requests.get(f'https://statsapi.mlb.com/api/v1.1/game/{game_list_input[i]}/feed/live')
159
+ # Append the JSON response to the data_total list
160
+ data_total.append(r.json())
 
 
 
161
 
162
  return data_total
163
 
164
+
165
  def get_data_df(self, data_list):
166
  """
167
  Converts a list of game data JSON objects into a Polars DataFrame.