nesticot commited on
Commit
85d6b4b
·
verified ·
1 Parent(s): 781beac

Upload api_scraper.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. api_scraper.py +28 -17
api_scraper.py CHANGED
@@ -154,30 +154,41 @@ class MLB_Scrape:
154
  return game_df
155
 
156
 
157
- def get_data(self, game_list_input: list):
158
- """
159
- Retrieves live game data for a list of game IDs in parallel.
160
 
161
- Parameters:
162
- - game_list_input (list): A list of game IDs for which to retrieve live data.
163
 
164
- Returns:
165
- - data_total (list): A list of JSON responses containing live game data for each game ID.
166
- """
167
- data_total = []
168
- print('This May Take a While. Progress Bar shows Completion of Data Retrieval.')
169
 
170
- def fetch_data(game_id):
171
- r = requests.get(f'https://statsapi.mlb.com/api/v1.1/game/{game_id}/feed/live')
172
- return r.json()
173
 
174
- with ThreadPoolExecutor() as executor:
175
- futures = {executor.submit(fetch_data, game_id): game_id for game_id in game_list_input}
176
- for future in tqdm(as_completed(futures), total=len(futures), desc="Processing", unit="iteration"):
177
- data_total.append(future.result())
178
 
 
 
 
 
 
 
 
 
 
 
179
  return data_total
180
 
 
181
  def get_data_df(self, data_list):
182
  """
183
  Converts a list of game data JSON objects into a Polars DataFrame.
 
154
  return game_df
155
 
156
 
157
+ # def get_data(self, game_list_input: list):
158
+ # """
159
+ # Retrieves live game data for a list of game IDs in parallel.
160
 
161
+ # Parameters:
162
+ # - game_list_input (list): A list of game IDs for which to retrieve live data.
163
 
164
+ # Returns:
165
+ # - data_total (list): A list of JSON responses containing live game data for each game ID.
166
+ # """
167
+ # data_total = []
168
+ # print('This May Take a While. Progress Bar shows Completion of Data Retrieval.')
169
 
170
+ # def fetch_data(game_id):
171
+ # r = requests.get(f'https://statsapi.mlb.com/api/v1.1/game/{game_id}/feed/live')
172
+ # return r.json()
173
 
174
+ # with ThreadPoolExecutor() as executor:
175
+ # futures = {executor.submit(fetch_data, game_id): game_id for game_id in game_list_input}
176
+ # for future in tqdm(as_completed(futures), total=len(futures), desc="Processing", unit="iteration"):
177
+ # data_total.append(future.result())
178
 
179
+ # return data_total
180
+
181
+
182
+ def get_data(self,game_list_input = [748540]):
183
+ data_total = []
184
+ #n_count = 0
185
+ print('This May Take a While. Progress Bar shows Completion of Data Retrieval.')
186
+ for i in tqdm(range(len(game_list_input)), desc="Processing", unit="iteration"):
187
+ r = requests.get(f'https://statsapi.mlb.com/api/v1.1/game/{game_list_input[i]}/feed/live')
188
+ data_total.append(r.json())
189
  return data_total
190
 
191
+
192
  def get_data_df(self, data_list):
193
  """
194
  Converts a list of game data JSON objects into a Polars DataFrame.