Beispiel #1
0
 def update_game(self, game, event, data=None):
     if data is None:
         data = parse_ical_nflgame(event)
     away_id = self.teams.getbynick(data['away']).id
     home_id = self.teams.getbynick(data['home']).id
     updated = False
     with transaction.manager:
         if game.away_id != away_id:
             game.away_id = away_id
             updated = True
         if game.home_id != home_id:
             game.home_id = home_id
             updated = True
         fields = ['summary', 'uid', 'description', 'location',
                   'start', 'end']
         for f in fields:
             if getattr(game, f) != data[f]:
                 setattr(game, f, data[f])
                 updated = True
         if game.game_class != data['class']:
             game.game_class = data['class']
             updated = True
         scores, away_score, home_score = data['scores']
         if scores:
             gs = self.session.query(NFLGameScore).get(game.id)
             if gs is None:
                 updated = True
                 gs = NFLGameScore()
                 gs.game_id = game.id
                 gs.away_score = away_score
                 gs.home_score = home_score
                 self.session.add(gs)
         game = self.session.merge(game)
     return game, updated
Beispiel #2
0
 def insert_new_game(self, event, data=None):
     if data is None:
         data = parse_ical_nflgame(event)
     with transaction.manager:
         g = NFLGame()
         away, home = data['away'], data['home']
         g.away_id = self.teams.getbynick(away).id
         g.home_id = self.teams.getbynick(home).id
         fields = ['summary', 'uid', 'description', 'location',
                   'start', 'end']
         for f in fields:
             setattr(g, f, data[f])
         g.game_class = data['class']
         self.session.add(g)
         scores, away_score, home_score = data['scores']
         if scores:
             g = self.session.merge(g)
             gs = NFLGameScore()
             gs.game_id = g.id
             gs.away_score = away_score
             gs.home_score = home_score
             self.session.add(gs)
     return self.session.merge(g)