Upload api_scraper.py with huggingface_hub
Browse files- api_scraper.py +22 -0
api_scraper.py
CHANGED
|
@@ -160,6 +160,28 @@ class MLB_Scrape:
|
|
| 160 |
|
| 161 |
|
| 162 |
def get_data(self, game_list_input: list):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
"""
|
| 164 |
Retrieves live game data for a list of game IDs in parallel.
|
| 165 |
|
|
|
|
| 160 |
|
| 161 |
|
| 162 |
def get_data(self, game_list_input: list):
|
| 163 |
+
"""
|
| 164 |
+
Retrieves live game data for a list of game IDs.
|
| 165 |
+
|
| 166 |
+
Parameters:
|
| 167 |
+
- game_list_input (list): A list of game IDs for which to retrieve live data.
|
| 168 |
+
|
| 169 |
+
Returns:
|
| 170 |
+
- data_total (list): A list of JSON responses containing live game data for each game ID.
|
| 171 |
+
"""
|
| 172 |
+
data_total = []
|
| 173 |
+
print('This May Take a While. Progress Bar shows Completion of Data Retrieval.')
|
| 174 |
+
|
| 175 |
+
# Iterate over the list of game IDs with a progress bar
|
| 176 |
+
for i in tqdm(range(len(game_list_input)), desc="Processing", unit="iteration"):
|
| 177 |
+
# Make a GET request to the MLB API for each game ID
|
| 178 |
+
r = requests.get(f'https://statsapi.mlb.com/api/v1.1/game/{game_list_input[i]}/feed/live')
|
| 179 |
+
# Append the JSON response to the data_total list
|
| 180 |
+
data_total.append(r.json())
|
| 181 |
+
|
| 182 |
+
return data_total
|
| 183 |
+
|
| 184 |
+
def get_data_new(self, game_list_input: list):
|
| 185 |
"""
|
| 186 |
Retrieves live game data for a list of game IDs in parallel.
|
| 187 |
|