[Bug]: Timeout Error
sportsstats opened this issue · 3 comments
NBA API Version
1.3.1
Issue
timeout Traceback (most recent call last)
~\anaconda3\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
444 # Otherwise it looks like a bug in the code.
--> 445 six.raise_from(e, None)
446 except (SocketTimeout, BaseSSLError, SocketError) as e:
~\anaconda3\lib\site-packages\urllib3\packages\six.py in raise_from(value, from_value)
~\anaconda3\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
439 try:
--> 440 httplib_response = conn.getresponse()
441 except BaseException as e:
~\anaconda3\lib\http\client.py in getresponse(self)
1370 try:
-> 1371 response.begin()
1372 except ConnectionError:
~\anaconda3\lib\http\client.py in begin(self)
318 while True:
--> 319 version, status, reason = self._read_status()
320 if status != CONTINUE:
~\anaconda3\lib\http\client.py in _read_status(self)
279 def _read_status(self):
--> 280 line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
281 if len(line) > _MAXLINE:
~\anaconda3\lib\socket.py in readinto(self, b)
703 try:
--> 704 return self._sock.recv_into(b)
705 except timeout:
~\anaconda3\lib\ssl.py in recv_into(self, buffer, nbytes, flags)
1240 self.class)
-> 1241 return self.read(nbytes, buffer)
1242 else:
~\anaconda3\lib\ssl.py in read(self, len, buffer)
1098 if buffer is not None:
-> 1099 return self._sslobj.read(len, buffer)
1100 else:
timeout: The read operation timed out
During handling of the above exception, another exception occurred:
ReadTimeoutError Traceback (most recent call last)
~\anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
485 try:
--> 486 resp = conn.urlopen(
487 method=request.method,
~\anaconda3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
754
--> 755 retries = retries.increment(
756 method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
~\anaconda3\lib\site-packages\urllib3\util\retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
531 if read is False or not self._is_method_retryable(method):
--> 532 raise six.reraise(type(error), error, _stacktrace)
533 elif read is not None:
~\anaconda3\lib\site-packages\urllib3\packages\six.py in reraise(tp, value, tb)
769 raise value.with_traceback(tb)
--> 770 raise value
771 finally:
~\anaconda3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
698 # Make the request on the httplib connection object.
--> 699 httplib_response = self._make_request(
700 conn,
~\anaconda3\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
446 except (SocketTimeout, BaseSSLError, SocketError) as e:
--> 447 self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
448 raise
~\anaconda3\lib\site-packages\urllib3\connectionpool.py in _raise_timeout(self, err, url, timeout_value)
335 if isinstance(err, SocketTimeout):
--> 336 raise ReadTimeoutError(
337 self, url, "Read timed out. (read timeout=%s)" % timeout_value
ReadTimeoutError: HTTPSConnectionPool(host='stats.nba.com', port=443): Read timed out. (read timeout=30)
During handling of the above exception, another exception occurred:
ReadTimeout Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_18104/3376019070.py in
488
489 while True:
--> 490 schedule.run_pending()
491 time.sleep(60) # wait one minute
~\anaconda3\lib\site-packages\schedule_init_.py in run_pending()
778 :data:default scheduler instance <default_scheduler>
.
779 """
--> 780 default_scheduler.run_pending()
781
782
~\anaconda3\lib\site-packages\schedule_init_.py in run_pending(self)
98 runnable_jobs = (job for job in self.jobs if job.should_run)
99 for job in sorted(runnable_jobs):
--> 100 self._run_job(job)
101
102 def run_all(self, delay_seconds: int = 0) -> None:
~\anaconda3\lib\site-packages\schedule_init_.py in _run_job(self, job)
170
171 def _run_job(self, job: "Job") -> None:
--> 172 ret = job.run()
173 if isinstance(ret, CancelJob) or ret is CancelJob:
174 self.cancel_job(job)
~\anaconda3\lib\site-packages\schedule_init_.py in run(self)
659
660 logger.debug("Running job %s", self)
--> 661 ret = self.job_func()
662 self.last_run = datetime.datetime.now()
663 self._schedule_next_run()
~\AppData\Local\Temp/ipykernel_18104/3376019070.py in job(t)
469
470 #vs WESTERN CONFERENCE Off Stats
--> 471 statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_conference_nullable=('West'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
472 stats=statfind.get_data_frames()[0]
473 stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
~\AppData\Roaming\Python\Python39\site-packages\nba_api\stats\endpoints\leaguedashteamstats.py in init(self, last_n_games, measure_type_detailed_defense, month, opponent_team_id, pace_adjust, per_mode_detailed, period, plus_minus, rank, season, season_type_all_star, conference_nullable, date_from_nullable, date_to_nullable, division_simple_nullable, game_scope_simple_nullable, game_segment_nullable, league_id_nullable, location_nullable, outcome_nullable, po_round_nullable, player_experience_nullable, player_position_abbreviation_nullable, season_segment_nullable, shot_clock_range_nullable, starter_bench_nullable, team_id_nullable, two_way_nullable, vs_conference_nullable, vs_division_nullable, proxy, headers, timeout, get_request)
86 }
87 if get_request:
---> 88 self.get_request()
89
90 def get_request(self):
~\AppData\Roaming\Python\Python39\site-packages\nba_api\stats\endpoints\leaguedashteamstats.py in get_request(self)
89
90 def get_request(self):
---> 91 self.nba_response = NBAStatsHTTP().send_api_request(
92 endpoint=self.endpoint,
93 parameters=self.parameters,
~\AppData\Roaming\Python\Python39\site-packages\nba_api\library\http.py in send_api_request(self, endpoint, parameters, referer, proxy, headers, timeout, raise_exception_on_error)
128
129 if not contents:
--> 130 response = requests.get(url=base_url, params=parameters, headers=request_headers, proxies=proxies, timeout=timeout)
131 url = response.url
132 status_code = response.status_code
~\anaconda3\lib\site-packages\requests\api.py in get(url, params, **kwargs)
71 """
72
---> 73 return request("get", url, params=params, **kwargs)
74
75
~\anaconda3\lib\site-packages\requests\api.py in request(method, url, **kwargs)
57 # cases, and look like a memory leak in others.
58 with sessions.Session() as session:
---> 59 return session.request(method=method, url=url, **kwargs)
60
61
~\anaconda3\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
587 }
588 send_kwargs.update(settings)
--> 589 resp = self.send(prep, **send_kwargs)
590
591 return resp
~\anaconda3\lib\site-packages\requests\sessions.py in send(self, request, **kwargs)
701
702 # Send the request
--> 703 r = adapter.send(request, **kwargs)
704
705 # Total elapsed time of the request (approximately)
~\anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
530 raise SSLError(e, request=request)
531 elif isinstance(e, ReadTimeoutError):
--> 532 raise ReadTimeout(e, request=request)
533 elif isinstance(e, _InvalidHeader):
534 raise InvalidHeader(e, request=request)
ReadTimeout: HTTPSConnectionPool(host='stats.nba.com', port=443): Read timed out. (read timeout=30)
Code
#from nba_api.stats.endpoints import leaguedashteamstats
import pandas as pd
import time
#from nba_api.stats.endpoints import *
from nba_api.stats.endpoints import leaguedashteamstats
import os
from datetime import datetime
import platform
import warnings
warnings.filterwarnings('ignore')
warnings.warn('DelftStack')
warnings.warn('Do not show this message')
import schedule
def job(t):
print("I'm working..."), t
from datetime import datetime
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print("Current Time =", current_time)
import time
st = time.time()
starttime = time.time()
import datetime
today = datetime.date.today()
yday = today - datetime.timedelta(days = 1)
print(yday)
datem = yday.strftime('%m')
datey = yday.strftime('%Y')
day = yday.strftime('%d')
print(datem)
print(datey)
print(day)
# import calendar
# calendar.monthrange(datey, datem)[1]
# # --> = Code to check before running
i = int(day)
# #i = 30
# # --> endate should be 2 days after last month day
# days31 = {1,3,5,7,8,10,12}
# feb = 2
datem = str(datem)
# if len(datem) == 1:
# datem = '0'+datem
enddate = int(day) +1
# --> Use <10 for Single Digit Days
#while (i <10):
# --> Use <32 or <31 for Double Digit Days
while (i < enddate):
cv = str(i)
if i <10:
# --> For Single Digit Days use '0'+cv
cv2 = '0'+cv
elif i >9 and i < 32:
# --> For Double Digit Days use cv
cv2 = cv
else:
os.system('say "your program has finished"')
break
# --> Make sure Month & Year Correct
CY = '2023_24'
DFrom = '10/24/2023'
DTo = str(datem) + "/" + cv2 + "/" + str(datey)
#DTo = "02/28/2022"
Y = DTo.replace("/", '')
SZN = '2023-24'
if platform.system() == 'Darwin':
#OFFENSE Stats
#HOME Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, location_nullable=('Home'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel('/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/'+CY+'/Offense/Home/NBAHomeOff'+Y+'.xls')
time.sleep(15)
#ROAD Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, location_nullable=('Road'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Offense/Road/NBARoadOff'+Y+'.xls')
time.sleep(2)
time.sleep(15)
#vs ATLANTIC DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, vs_division_nullable=('Atlantic'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Offense/vsAtlantic/NBAvsAtlanticOff'+Y+'.xls')
time.sleep(15)
#vs CENTRAL DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, vs_division_nullable=('Central'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Offense/vsCentral/NBAvsCentralOff'+Y+'.xls')
time.sleep(2)
time.sleep(15)
#vs NORTHWEST DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, vs_division_nullable=('Northwest'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Offense/vsNorthwest/NBAvsNorthwestOff'+Y+'.xls')
time.sleep(15)
#vs PACIFIC DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, vs_division_nullable=('Pacific'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Offense/vsPacific/NBAvsPacificOff'+Y+'.xls')
time.sleep(2)
time.sleep(15)
#vs SOUTHEAST DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, vs_division_nullable=('Southeast'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Offense/vsSoutheast/NBAvsSoutheastOff'+Y+'.xls')
time.sleep(15)
#vs SOUTHWEST DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, vs_division_nullable=('Southwest'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Offense/vsSouthwest/NBAvsSouthwestOff'+Y+'.xls')
time.sleep(2)
time.sleep(15)
#vs EASTERN CONFERENCE Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, vs_conference_nullable=('East'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Offense/vsEast/NBAvsEastConfOff'+Y+'.xls')
time.sleep(15)
#vs WESTERN CONFERENCE Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, vs_conference_nullable=('West'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Offense/vsWest/NBAvsWestConfOff'+Y+'.xls')
time.sleep(2)
#-------------------------------------
#DEFENSE Opp Stats
time.sleep(15)
#Home Opp Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, location_nullable=('Home'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Defense/Home/NBAHomeDef'+Y+'.xls')
time.sleep(15)
#ROAD Opp Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, location_nullable=('Road'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Defense/Road/NBARoadDef'+Y+'.xls')
time.sleep(2)
time.sleep(15)
#vs ATLANTIC DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_division_nullable=('Atlantic'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Defense/vsAtlantic/NBAvsAtlanticDef'+Y+'.xls')
time.sleep(15)
#vs CENTRAL DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_division_nullable=('Central'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Defense/vsCentral/NBAvsCentralDef'+Y+'.xls')
time.sleep(2)
time.sleep(15)
#vs NORTHWEST DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_division_nullable=('Northwest'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Defense/vsNorthwest/NBAvsNorthwestDef'+Y+'.xls')
time.sleep(15)
#vs PACIFIC DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_division_nullable=('Pacific'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Defense/vsPacific/NBAvsPacificDef'+Y+'.xls')
time.sleep(2)
time.sleep(15)
#vs SOUTHEAST DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_division_nullable=('Southeast'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Defense/vsSoutheast/NBAvsSoutheastDef'+Y+'.xls')
time.sleep(15)
#vs SOUTHWEST DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_division_nullable=('Southwest'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Defense/vsSouthwest/NBAvsSouthwestDef'+Y+'.xls')
time.sleep(2)
time.sleep(15)
#vs EASTERN CONFERENCE Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_conference_nullable=('East'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Defense/vsEast/NBAvsEastConfDef'+Y+'.xls')
time.sleep(15)
#vs WESTERN CONFERENCE Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_conference_nullable=('West'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("/Users/Fleet/Library/CloudStorage/GoogleDrive/My Drive/Sports/NBA/"+CY+'/Defense/vsWest/NBAvsWestConfDef'+Y+'.xls')
print(i)
time.sleep(2)
i=i+1
else:
#OFFENSE Stats
time.sleep(15)
#HOME Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, location_nullable=('Home'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+"/Offense/Home/NBAHomeOff"+Y+".xls")
time.sleep(15)
#ROAD Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, location_nullable=('Road'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Offense/Road/NBARoadOff'+Y+'.xls')
time.sleep(2)
time.sleep(15)
#vs ATLANTIC DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, vs_division_nullable=('Atlantic'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Offense/vsAtlantic/NBAvsAtlanticOff'+Y+'.xls')
time.sleep(15)
#vs CENTRAL DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, vs_division_nullable=('Central'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Offense/vsCentral/NBAvsCentralOff'+Y+'.xls')
time.sleep(2)
time.sleep(15)
#vs NORTHWEST DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, vs_division_nullable=('Northwest'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Offense/vsNorthwest/NBAvsNorthwestOff'+Y+'.xls')
time.sleep(15)
#vs PACIFIC DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, vs_division_nullable=('Pacific'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Offense/vsPacific/NBAvsPacificOff'+Y+'.xls')
time.sleep(2)
time.sleep(15)
#vs SOUTHEAST DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, vs_division_nullable=('Southeast'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Offense/vsSoutheast/NBAvsSoutheastOff'+Y+'.xls')
time.sleep(15)
#vs SOUTHWEST DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, vs_division_nullable=('Southwest'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Offense/vsSouthwest/NBAvsSouthwestOff'+Y+'.xls')
time.sleep(2)
time.sleep(15)
#vs EASTERN CONFERENCE Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, vs_conference_nullable=('East'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Offense/vsEast/NBAvsEastConfOff'+Y+'.xls')
time.sleep(15)
#vs WESTERN CONFERENCE Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, date_to_nullable=DTo, vs_conference_nullable=('West'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Offense/vsWest/NBAvsWestConfOff'+Y+'.xls')
time.sleep(2)
#-------------------------------------
#DEFENSE Opp Stats
time.sleep(15)
#Home Opp Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, location_nullable=('Home'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Defense/Home/NBAHomeDef'+Y+'.xls')
time.sleep(15)
#ROAD Opp Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, location_nullable=('Road'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Defense/Road/NBARoadDef'+Y+'.xls')
time.sleep(2)
time.sleep(15)
#vs ATLANTIC DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_division_nullable=('Atlantic'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Defense/vsAtlantic/NBAvsAtlanticDef'+Y+'.xls')
time.sleep(15)
#vs CENTRAL DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_division_nullable=('Central'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Defense/vsCentral/NBAvsCentralDef'+Y+'.xls')
time.sleep(2)
time.sleep(15)
#vs NORTHWEST DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_division_nullable=('Northwest'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Defense/vsNorthwest/NBAvsNorthwestDef'+Y+'.xls')
time.sleep(15)
#vs PACIFIC DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_division_nullable=('Pacific'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Defense/vsPacific/NBAvsPacificDef'+Y+'.xls')
time.sleep(2)
time.sleep(15)
#vs SOUTHEAST DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_division_nullable=('Southeast'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Defense/vsSoutheast/NBAvsSoutheastDef'+Y+'.xls')
time.sleep(15)
#vs SOUTHWEST DIVISION Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_division_nullable=('Southwest'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Defense/vsSouthwest/NBAvsSouthwestDef'+Y+'.xls')
time.sleep(2)
time.sleep(15)
#vs EASTERN CONFERENCE Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_conference_nullable=('East'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Defense/vsEast/NBAvsEastConfDef'+Y+'.xls')
time.sleep(15)
#vs WESTERN CONFERENCE Off Stats
statfind = leaguedashteamstats.LeagueDashTeamStats(season=SZN, measure_type_detailed_defense=('Opponent'),date_to_nullable=DTo, vs_conference_nullable=('West'),date_from_nullable=DFrom,per_mode_detailed='PerGame')
stats=statfind.get_data_frames()[0]
stats.rename(columns={'CFPARAMS': 'TEAM_NAME'})
stats = stats.replace('Portland Trail Blazers','Portland Trailblazers')
stats.to_excel("G:/My Drive/Sports/NBA/"+CY+'/Defense/vsWest/NBAvsWestConfDef'+Y+'.xls')
print(i)
time.sleep(2)
i=i+1
etime = time.time() - starttime
print('Execution time:', time.strftime("%H:%M:%S", time.gmtime(etime)))
os.system('say "your NBA program has finished"')
return
schedule.every().day.at("11:35").do(job,'It is 05:00')
while True:
schedule.run_pending()
time.sleep(60) # wait one minute
Been running the code like this for a few years with no issues until today.
Issue resolved, it's now working