nesticot commited on
Commit
608f363
·
verified ·
1 Parent(s): 110cc23

Update api_scraper.py

Browse files
Files changed (1) hide show
  1. api_scraper.py +9 -10
api_scraper.py CHANGED
@@ -141,7 +141,7 @@ class MLB_Scrape:
141
 
142
  def get_data(self, game_list_input: list):
143
  """
144
- Retrieves live game data for a list of game IDs in parallel.
145
 
146
  Parameters:
147
  - game_list_input (list): A list of game IDs for which to retrieve live data.
@@ -152,16 +152,15 @@ class MLB_Scrape:
152
  data_total = []
153
  print('This May Take a While. Progress Bar shows Completion of Data Retrieval.')
154
 
155
- def fetch_data(game_id):
156
- r = requests.get(f'https://statsapi.mlb.com/api/v1.1/game/{game_id}/feed/live')
157
- return r.json()
158
-
159
- with ThreadPoolExecutor() as executor:
160
- futures = {executor.submit(fetch_data, game_id): game_id for game_id in game_list_input}
161
- for future in tqdm(as_completed(futures), total=len(futures), desc="Processing", unit="iteration"):
162
- data_total.append(future.result())
163
- time.sleep(0.05)
164
 
 
 
165
 
166
  return data_total
167
 
 
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
  return data_total
166