def _save_scores(self, week, scores): query = Score.all() scorebox = {} result = {} query.filter('week =', week) result = query.fetch(25) if len(result) <= 0: # Completely new save for game in scores: scorebox = Score( year = self.get_season_year(), week = week, away_name = game[AWAY_NAME].encode('ascii', 'ignore'), away_score = int(game[AWAY_SCORE]), game_clock = str(game[GAME_CLOCK]), game_day = game[GAME_DAY].encode('ascii', 'ignore'), game_id = int(game[GAME_ID]), game_status = game[GAME_STATUS], game_time = game[GAME_TIME], home_name = game[HOME_NAME].encode('ascii', 'ignore'), home_score = int(game[HOME_SCORE]), timestamp = datetime.datetime.now() ) scorebox.put() else: current = {} for scorebox in result: # Find the related game score for game in scores: if game[AWAY_NAME] == scorebox.away_name: current = game break key = scorebox.key() matchup = Score.get(key) # Update matchup.away_score = int(current[AWAY_SCORE]) matchup.home_score = int(current[HOME_SCORE]) matchup.game_clock = str(current[GAME_CLOCK]) matchup.game_status = current[GAME_STATUS] matchup.timestamp = datetime.datetime.now() #Push update matchup.put()
def _save_scores(self, week, scores): query = Score.all() scorebox = {} result = {} query.filter('week =', week) result = query.fetch(25) if len(result) <= 0: # Completely new save for game in scores: scorebox = Score( year=self.get_season_year(), week=week, away_name=game[AWAY_NAME].encode('ascii', 'ignore'), away_score=int(game[AWAY_SCORE]), game_clock=str(game[GAME_CLOCK]), game_day=game[GAME_DAY].encode('ascii', 'ignore'), game_id=int(game[GAME_ID]), game_status=game[GAME_STATUS], game_time=game[GAME_TIME], home_name=game[HOME_NAME].encode('ascii', 'ignore'), home_score=int(game[HOME_SCORE]), timestamp=datetime.datetime.now()) scorebox.put() else: current = {} for scorebox in result: # Find the related game score for game in scores: if game[AWAY_NAME] == scorebox.away_name: current = game break key = scorebox.key() matchup = Score.get(key) # Update matchup.away_score = int(current[AWAY_SCORE]) matchup.home_score = int(current[HOME_SCORE]) matchup.game_clock = str(current[GAME_CLOCK]) matchup.game_status = current[GAME_STATUS] matchup.timestamp = datetime.datetime.now() #Push update matchup.put()
def _save_scores(self, week, scores): ''' Side-Effect: Appends a game's margin & odds ''' current = {} _game_status = '' key = None matchup = None query = Score.all() query_select = {} scorebox = {} right_now = (datetime.datetime.now() - datetime.timedelta(hours=constants.UTC_OFFSET)) query.filter('week =', week) query_select = query.fetch(constants.TOTAL_TEAMS) if len(query_select) == 0: # Completely new save for game in scores: _game_status = game[constants.GAME_STATUS] if _game_status == 'final overtime': # Workaround for formatting regarding overtime games _game_status = 'Final Overtime' scorebox = Score( year = int(game[constants.GAME_SEASON]), week = int(week), away_name = game[constants.AWAY_NAME].encode('ascii', 'ignore'), away_score = int(game[constants.AWAY_SCORE]), game_clock = str(game[constants.GAME_CLOCK]), game_day = game[constants.GAME_DAY].encode('ascii', 'ignore'), game_id = int(game[constants.GAME_ID]), game_status = _game_status, game_time = game[constants.GAME_TIME], home_name = game[constants.HOME_NAME].encode('ascii', 'ignore'), home_score = int(game[constants.HOME_SCORE]), spread_margin = float(game[constants.GAME_SPREAD_MARGIN]), spread_odds = float(game[constants.GAME_SPREAD_ODDS]), timestamp = right_now ) scorebox.put() else: # Update the scores for scorebox in query_select: # Find the related game score for game in scores: if game[constants.AWAY_NAME] == scorebox.away_name: current = game break key = scorebox.key() matchup = Score.get(key) # Update matchup.away_score = int(game[constants.AWAY_SCORE]) matchup.game_clock = str(game[constants.GAME_CLOCK]) matchup.game_status = game[constants.GAME_STATUS] matchup.home_score = int(game[constants.HOME_SCORE]) matchup.timestamp = right_now # Pull margin & odds data while we have the data game[constants.GAME_SPREAD_MARGIN] = matchup.spread_margin game[constants.GAME_SPREAD_ODDS] = matchup.spread_odds # Push update matchup.put()
def _save_scores(self, week, scores): ''' Side-Effect: Appends a game's margin & odds ''' current = {} _game_status = '' key = None matchup = None query = Score.all() query_select = {} scorebox = {} right_now = (datetime.datetime.now() - datetime.timedelta(hours=constants.UTC_OFFSET)) query.filter('week =', week) query_select = query.fetch(constants.TOTAL_TEAMS) if len(query_select) == 0: # Completely new save for game in scores: _game_status = game[constants.GAME_STATUS] if _game_status == 'final overtime': # Workaround for formatting regarding overtime games _game_status = 'Final Overtime' scorebox = Score( year=int(game[constants.GAME_SEASON]), week=int(week), away_name=game[constants.AWAY_NAME].encode( 'ascii', 'ignore'), away_score=int(game[constants.AWAY_SCORE]), game_clock=str(game[constants.GAME_CLOCK]), game_day=game[constants.GAME_DAY].encode( 'ascii', 'ignore'), game_id=int(game[constants.GAME_ID]), game_status=_game_status, game_time=game[constants.GAME_TIME], home_name=game[constants.HOME_NAME].encode( 'ascii', 'ignore'), home_score=int(game[constants.HOME_SCORE]), spread_margin=float(game[constants.GAME_SPREAD_MARGIN]), spread_odds=float(game[constants.GAME_SPREAD_ODDS]), timestamp=right_now) scorebox.put() else: # Update the scores for scorebox in query_select: # Find the related game score for game in scores: if game[constants.AWAY_NAME] == scorebox.away_name: current = game break key = scorebox.key() matchup = Score.get(key) # Update matchup.away_score = int(game[constants.AWAY_SCORE]) matchup.game_clock = str(game[constants.GAME_CLOCK]) matchup.game_status = game[constants.GAME_STATUS] matchup.home_score = int(game[constants.HOME_SCORE]) matchup.timestamp = right_now # Pull margin & odds data while we have the data game[constants.GAME_SPREAD_MARGIN] = matchup.spread_margin game[constants.GAME_SPREAD_ODDS] = matchup.spread_odds # Push update matchup.put()