Update api_scraper.py
Browse files- 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
|
| 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 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 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 |
|