Browse Source

Catch days without games and pause loop

cryobry 4 years ago
parent
commit
d6e6c2cca1
1 changed files with 21 additions and 6 deletions
  1. 21 6
      nba_playoffs_game_updater.py

+ 21 - 6
nba_playoffs_game_updater.py

@@ -34,9 +34,9 @@ def _getStatsSheet(_key):
   _numParticipants = _leaderSheet.row_count - 1
   # return stats worksheet
   return _statsSheet, _numParticipants
+  
 
-
-def _getPlayersCells(_statsSheet, _numParticipants):
+def _getRowsFromDate(_statsSheet, _numParticipants):
   
   # get today
   _today = datetime.date.today()
@@ -52,15 +52,23 @@ def _getPlayersCells(_statsSheet, _numParticipants):
   # get date cells
   while _startRow <= _shtRows:
     _dateCell = _statsSheet.cell(_startRow, 1, value_render_option='UNFORMATTED_VALUE')
-    _daysSince1900 = _dateCell.value
+    _daysSince1900 = _dateCell.value    
     _date = datetime.date(1899, 12, 30) + datetime.timedelta(int(_daysSince1900))
-    
+
     if _today == _date:
       break
-    else:
+    elif _today > _date:
       _startRow += _numParticipants
+    else:
+      _startRow = 0
+      break
       
   _lastRow = _startRow + _numParticipants - 1
+  
+  return _startRow, _lastRow
+
+
+def _getPlayersCells(_statsSheet, _startRow, _lastRow):
    
   # get todays players
    
@@ -158,7 +166,13 @@ while True:
 
   try:
     _statsSheet, _numParticipants = _getStatsSheet(_spreadsheetKey)
-    _playersCells, _urlDate = _getPlayersCells(_statsSheet, _numParticipants)
+    _startRow, _lastRow = _getRowsFromDate(_statsSheet, _numParticipants)
+    if _startRow == 0:
+      print("No games today! Pausing for 1000s")
+      time.sleep(1000)
+      continue
+    else:
+      _playersCells, _urlDate = _getPlayersCells(_statsSheet, _startRow, _lastRow)
   except gspread.exceptions.APIError:
     print("API overloaded, adding a 100 second delay...")
     time.sleep(100)
@@ -168,6 +182,7 @@ while True:
     continue
 
   for _playerCell in _playersCells:
+  
     while True:
     
       try: