@@ -518,7 +518,7 @@ def _update_points(self, result):
518518 self .points = score
519519 self .save ()
520520
521- def update_results (self , results ):
521+ def update_results (self , results , overwrite = False ):
522522 """
523523 results schema: {'sequence': 1, 'season': 2018, 'games': [{
524524 "home": "HOME",
@@ -544,12 +544,30 @@ def update_results(self, results):
544544
545545 count = 0
546546 all_games = list (self .games .select_related ("home" , "away" ))
547- incomplete_games = [
548- g for g in all_games if g .home .abbr in completed and g .status == g .Status .UNPLAYED
549- ]
550- for game in incomplete_games :
547+
548+ def get_score (value ):
549+ if isinstance (value , int ):
550+ return value
551+
552+ if isinstance (value , str ) and value .isdigit ():
553+ return int (value )
554+
555+ return 0
556+
557+ if overwrite :
558+ games_to_update = all_games
559+ else :
560+ games_to_update = [
561+ g
562+ for g in all_games
563+ if g .home and (g .home .abbr in completed ) and g .status == g .Status .UNPLAYED
564+ ]
565+
566+ for game in games_to_update :
551567 result = completed .get (game .home .abbr , None )
552568 if result :
569+ game .home_score = get_score (result .get ("home_score" ))
570+ game .away_score = get_score (result .get ("away_score" ))
553571 winner = result ["winner" ]
554572 game .winner = (
555573 game .home
@@ -573,7 +591,9 @@ def winners(self, group):
573591 yield r .picker
574592
575593 def pickset_query (self , group ):
576- return self .picksets .filter (picker__picker_memberships__group = group ).select_related ("picker" )
594+ return self .picksets .filter (picker__picker_memberships__group = group ).select_related (
595+ "picker"
596+ )
577597
578598 def update_pick_status (self ):
579599 for group in PickerGrouping .objects .active ():
0 commit comments