Browse Source

Refactor and clean

cryobry 4 years ago
parent
commit
2e40f8ef85
1 changed files with 14 additions and 35 deletions
  1. 14 35
      nba_playoffs_game_updater.py

+ 14 - 35
nba_playoffs_game_updater.py

@@ -11,7 +11,6 @@ import time
 
 import timeout_decorator
 
-#_spreadsheetKey = "1wX5ilnky-YDfa2lTLcLYHpGq1UOLkUI5Ii9cIZeAZVI"
 _spreadsheetKey = "12Zv95ZMJ008KXC5ytVnBusjX9wUnpOg0TOLwmxMNOTQ"
 
 ####### GET SHEETS AND NUM PARTICIPANTS #######
@@ -26,13 +25,14 @@ def _getStatsSheet(_key):
 
   # open spreadsheet
   _spreadsheet = _gc.open_by_key(_key)
+  
   # open worksheet
   _statsSheet = _spreadsheet.get_worksheet(0)
   _leaderSheet = _spreadsheet.get_worksheet(1)
   
   # count participants
   _numParticipants = _leaderSheet.row_count - 1
-  # return stats worksheet
+
   return _statsSheet, _numParticipants
   
 
@@ -41,6 +41,7 @@ def _getRowsFromDate(_statsSheet, _numParticipants):
   # get today
   _today = datetime.date.today()
   #_today = datetime.date(2018, 5, 2)
+  
   _urlDate = _today.strftime('%m/%d/%Y')
 
   # count rows
@@ -60,47 +61,27 @@ def _getRowsFromDate(_statsSheet, _numParticipants):
     elif _today > _date:
       _startRow += _numParticipants
     else:
-      _startRow = 0
+      _startRow = 0 # no games today
       break
       
   _lastRow = _startRow + _numParticipants - 1
   
-  return _startRow, _lastRow
+  return _startRow, _lastRow, _urlDate
 
 
 def _getPlayersCells(_statsSheet, _startRow, _lastRow):
    
-  # get todays players
-   
   _playersCells = _statsSheet.range(_startRow, 3, _lastRow, 3)
-   
+  
   # filter cells
-   
   for _playerCell in _playersCells[:]:
 
-    while True:
-      try:
-        # remove empty cells
-        if _playerCell.value == "":
-          _playersCells.remove(_playerCell)
+    if _playerCell.value == "":
+      _playersCells.remove(_playerCell)
           break
-          
-        # remove finished games
-        #_rowNumber = _playerCell.row
-        #_wlCell = _statsSheet.cell(_rowNumber, 11)
-        #if _wlCell.value != "":
-          #_playersCells.remove(_playerCell)
-          #break
-      except gspread.exceptions.APIError:
-        print("API overloaded, adding a 100 second delay...")
-        time.sleep(100)
-        continue
-      break
-
-  return _playersCells, _urlDate
-
-
-####### PARSE PLAYERS #######
+  
+  return _playersCells
+  
 
 def _getPlayerFirstNameLastName(_player):
   _firstNamelastName = _player.split()
@@ -108,6 +89,7 @@ def _getPlayerFirstNameLastName(_player):
   _firstName = _firstName.replace('.', '')
   _lastName = _firstNamelastName[1]
   return _firstName, _lastName
+  
 
 @timeout_decorator.timeout(10)  
 def _getPlayerID(_firstName, _lastName):
@@ -115,7 +97,6 @@ def _getPlayerID(_firstName, _lastName):
   return _playerID
 
 
-####### GET STATS #######
 @timeout_decorator.timeout(10)
 def _getPlayerStats(_playerID, _urlDate):
 
@@ -132,8 +113,6 @@ def _getPlayerStats(_playerID, _urlDate):
   return _playerStats
 
 
-####### UPDATE PLAYER STATS CELLS #######
-
 def _updatePlayerStatsCells(_statsSheet, _playerCell, _playerStats):
 
   _rowNumber = _playerCell.row
@@ -166,13 +145,13 @@ while True:
 
   try:
     _statsSheet, _numParticipants = _getStatsSheet(_spreadsheetKey)
-    _startRow, _lastRow = _getRowsFromDate(_statsSheet, _numParticipants)
+    _startRow, _lastRow, _urlDate = _getRowsFromDate(_statsSheet, _numParticipants)
     if _startRow == 0:
       print("No games today! Pausing for 1000s")
       time.sleep(1000)
       continue
     else:
-      _playersCells, _urlDate = _getPlayersCells(_statsSheet, _startRow, _lastRow)
+      _playersCells = _getPlayersCells(_statsSheet, _startRow, _lastRow)
   except gspread.exceptions.APIError:
     print("API overloaded, adding a 100 second delay...")
     time.sleep(100)