Exemplo n.º 1
0
    def import_game(self, game_row, league):
        # league_abbreviation = game_row[0].text
        number = int(game_row[1].text)

        if self.options['games'] and number not in self.options['games']:
            self.stdout.write('SKIPPING Game: {} (options)'.format(number))
            return

        opening_whistle = parsing.parse_opening_whistle(game_row[2].text)
        sports_hall = self.get_sports_hall(game_row)
        home_team = Team.objects.get(league=league,
                                     short_name=game_row[4].text)
        guest_team = Team.objects.get(league=league,
                                      short_name=game_row[6].text)
        home_goals, guest_goals = parsing.parse_goals(game_row)
        report_number = parsing.parse_report_number(game_row[10])
        forfeiting_team = parsing.parse_forfeiting_team(
            game_row[10], home_team, guest_team)

        if not Game.objects.filter(number=number).exists():
            self.stdout.write('CREATING Game: {}'.format(number))
            game = Game.objects.create(number=number,
                                       league=league,
                                       opening_whistle=opening_whistle,
                                       sports_hall=sports_hall,
                                       home_team=home_team,
                                       guest_team=guest_team,
                                       home_goals=home_goals,
                                       guest_goals=guest_goals,
                                       report_number=report_number,
                                       forfeiting_team=forfeiting_team)
            self.stdout.write('CREATED Game: {}'.format(game))

        else:
            self.stdout.write('EXISTING Game: {}'.format(number))
            game = Game.objects.get(number=number)
            if game.opening_whistle != opening_whistle:
                self.stdout.write(
                    'UPDATING Game opening whistle: {}'.format(game))
                game.opening_whistle = opening_whistle
            if game.sports_hall != sports_hall:
                self.stdout.write('UPDATING Game Sports Hall: {}'.format(game))
                game.sports_hall = sports_hall
            if game.home_goals != home_goals or game.guest_goals != guest_goals:
                self.stdout.write('UPDATING Game goals: {}'.format(game))
                game.home_goals = home_goals
                game.guest_goals = guest_goals
                Score.objects.filter(game=game).delete()
                self.stdout.write('DELETED Game Scores: {}'.format(game))
            if game.report_number != report_number:
                self.stdout.write(
                    'UPDATING Game report number: {}'.format(game))
                game.report_number = report_number
                self.stdout.write('DELETED Game Scores: {}'.format(game))
                Score.objects.filter(game=game).delete()
            if game.forfeiting_team != forfeiting_team:
                self.stdout.write(
                    'UPDATING Game forfeiting team: {}'.format(game))
                game.forfeiting_team = forfeiting_team
            game.save()
Exemplo n.º 2
0
    def test_dynamic_date(self):
        datetime_text = 'Di, 06.03.18, 03:54h'

        actual = parse_opening_whistle(datetime_text)

        expected = datetime(2018, 3, 6, 3, 54, 0)

        self.assertEqual(expected, actual)
Exemplo n.º 3
0
    def test_fixed_date(self):
        datetime_text = 'Sa, 09.09.17, 19:30h'

        actual = parse_opening_whistle(datetime_text)

        expected = datetime(2017, 9, 9, 19, 30, 0)

        self.assertEqual(expected, actual)
Exemplo n.º 4
0
    def import_game(self, game_row, league: League):

        if game_row[1].text == 'Nr.':
            LOGGER.debug('SKIPPING Row (heading)')
            return

        number = int(game_row[1].text)

        if self.options['games'] and number not in self.options['games']:
            LOGGER.debug('SKIPPING Game (options): %s', number)
            return

        opening_whistle = parsing.parse_opening_whistle(game_row[2].text)
        sports_hall = get_sports_hall(game_row)
        home_team = Team.objects.get(league=league,
                                     short_name=game_row[4].text)
        guest_team = Team.objects.get(league=league,
                                      short_name=game_row[6].text)
        home_goals, guest_goals = parsing.parse_goals(game_row)
        report_number = parsing.parse_report_number(game_row[10])
        forfeiting_team = parsing.parse_forfeiting_team(
            game_row[10], home_team, guest_team)

        if not Game.objects.filter(number=number,
                                   league__season=league.season).exists():
            LOGGER.debug('CREATING Game: %s', number)
            game = Game.objects.create(number=number,
                                       league=league,
                                       opening_whistle=opening_whistle,
                                       sports_hall=sports_hall,
                                       home_team=home_team,
                                       guest_team=guest_team,
                                       home_goals=home_goals,
                                       guest_goals=guest_goals,
                                       report_number=report_number,
                                       forfeiting_team=forfeiting_team)
            LOGGER.info('CREATED Game: %s', game)

        else:
            LOGGER.info('EXISTING Game: %s %s', number, league)
            game = Game.objects.get(number=number, league=league)
            if game.opening_whistle != opening_whistle:
                LOGGER.debug('UPDATING Game opening whistle: %s', game)
                game.opening_whistle = opening_whistle
            if game.sports_hall != sports_hall:
                LOGGER.debug('UPDATING Game Sports Hall: %s', game)
                game.sports_hall = sports_hall
            if game.home_goals != home_goals or game.guest_goals != guest_goals:
                LOGGER.debug('UPDATING Game goals: %s', game)
                game.home_goals = home_goals
                game.guest_goals = guest_goals
                Score.objects.filter(game=game).delete()
                LOGGER.debug('DELETED Game Scores: %s', game)
            if game.report_number != report_number:
                LOGGER.debug('UPDATING Game report number: %s', game)
                game.report_number = report_number
                LOGGER.debug('DELETED Game Scores: %s', game)
                Score.objects.filter(game=game).delete()
            if game.forfeiting_team != forfeiting_team:
                LOGGER.debug('UPDATING Game forfeiting team: %s', game)
                game.forfeiting_team = forfeiting_team
            game.save()
Exemplo n.º 5
0
    def test_date_not_null(self):
        datetime_text = 'Sa, 09.09.17, 19:30h'

        actual = parse_opening_whistle(datetime_text)

        self.assertNotEqual(None, actual)