Update functions/pitch_summary_functions.py
Browse files
functions/pitch_summary_functions.py
CHANGED
|
@@ -1015,21 +1015,21 @@ def fangraphs_pitching_leaderboards(season: int,
|
|
| 1015 |
print(start_date,end_date)
|
| 1016 |
print(f'{season}-01-01',f'{season}-12-31')
|
| 1017 |
|
| 1018 |
-
if (start_date_input == f'{season}-01-01' and end_date_input == f'{season}-12-31') and (season==get_current_year()):
|
| 1019 |
-
|
| 1020 |
-
url = f"""
|
| 1021 |
-
https://www.fangraphs.com/api/leaders/major-league/data?age=&pos=all&stats=pit&lg=all&season={season}&season1={season}
|
| 1022 |
-
&startdate={start_date}&enddate={end_date}&ind=0&qual=0&type=8&month=33&pageitems=500000
|
| 1023 |
-
"""
|
| 1024 |
-
|
| 1025 |
else:
|
| 1026 |
-
url = f"""
|
| 1027 |
-
|
| 1028 |
-
&startdate={start_date}&enddate={end_date}&ind=0&qual=0&type=8&month=1000&pageitems=500000
|
| 1029 |
-
"""
|
| 1030 |
-
|
| 1031 |
data = requests.get(url).json()
|
| 1032 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1033 |
return df
|
| 1034 |
|
| 1035 |
def fangraphs_splits_scrape(player_input: str, year_input: int, start_date: str, end_date: str, split: str,start_date_input:str = None,
|
|
|
|
| 1015 |
print(start_date,end_date)
|
| 1016 |
print(f'{season}-01-01',f'{season}-12-31')
|
| 1017 |
|
| 1018 |
+
if (start_date_input == f'{season}-01-01' and end_date_input == f'{season}-12-31') and (season == get_current_year()):
|
| 1019 |
+
url = f"""https://www.fangraphs.com/api/leaders/major-league/data?age=&pos=all&stats=pit&lg=all&season={season}&season1={season}&startdate={start_date}&enddate={end_date}&ind=0&qual=0&type=8&month=33&pageitems=500000"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1020 |
else:
|
| 1021 |
+
url = f"""https://www.fangraphs.com/api/leaders/major-league/data?age=&pos=all&stats=pit&lg=all&season={season}&season1={season}&startdate={start_date}&enddate={end_date}&ind=0&qual=0&type=8&month=1000&pageitems=500000"""
|
| 1022 |
+
|
|
|
|
|
|
|
|
|
|
| 1023 |
data = requests.get(url).json()
|
| 1024 |
+
|
| 1025 |
+
try:
|
| 1026 |
+
df = pl.DataFrame(data=data['data'], infer_schema_length=1000)
|
| 1027 |
+
except KeyError:
|
| 1028 |
+
# Retry with month=0 instead of 33
|
| 1029 |
+
url = f"""https://www.fangraphs.com/api/leaders/major-league/data?age=&pos=all&stats=pit&lg=all&season={season}&season1={season}&startdate={start_date}&enddate={end_date}&ind=0&qual=0&type=8&month=0&pageitems=500000"""
|
| 1030 |
+
data = requests.get(url).json()
|
| 1031 |
+
df = pl.DataFrame(data=data['data'], infer_schema_length=1000)
|
| 1032 |
+
|
| 1033 |
return df
|
| 1034 |
|
| 1035 |
def fangraphs_splits_scrape(player_input: str, year_input: int, start_date: str, end_date: str, split: str,start_date_input:str = None,
|