Exemplo n.º 1
0
    def create_league(self, league_link, district, season):
        abbreviation = league_link.text
        bhv_id = parsing.parse_league_bhv_id(league_link)

        if self.options['leagues'] and bhv_id not in self.options['leagues']:
            self.stdout.write('SKIPPING League (options): {} {}'.format(
                bhv_id, abbreviation))
            return

        if abbreviation[:1] in ['m', 'w', 'g', 'u'
                                ] and not self.options['youth']:
            self.stdout.write('SKIPPING League (youth league): {} {}'.format(
                bhv_id, abbreviation))
            return

        url = League.build_source_url(bhv_id)
        dom = logic.get_html(url)

        name = parsing.parse_league_name(dom)

        if League.is_youth_league(name) and not self.options['youth']:
            self.stdout.write('SKIPPING League (youth league): {} {}'.format(
                bhv_id, name))
            return

        team_links = dom.xpath('//table[@class="scoretable"]/tr[position() > 1]/td[3]/a') or \
                     dom.xpath('//table[@class="scoretable"]/tr[position() > 1]/td[2]/a')
        if not team_links:
            self.stdout.write('SKIPPING League: {} {} (no team table)'.format(
                bhv_id, name))
            return

        game_rows = parsing.parse_game_rows(dom)
        if not game_rows:
            self.stdout.write('SKIPPING League (no games): {} {}'.format(
                bhv_id, name))
            return
        if len(game_rows) < len(team_links) * (len(team_links) - 1):
            self.stdout.write('SKIPPING League (few games): {} {}'.format(
                bhv_id, abbreviation))
            return

        league, league_created = League.objects.get_or_create(
            name=name,
            abbreviation=abbreviation,
            district=district,
            season=season,
            bhv_id=bhv_id)
        if league_created:
            self.stdout.write('CREATED League: {}'.format(league))
        else:
            self.stdout.write('EXISTING League: {}'.format(league))

        for team_link in team_links:
            self.create_team(team_link, league)
Exemplo n.º 2
0
    def setUp(self):
        user = User(username='******')
        user.set_password('rabble')
        user.save()
        self.user = user
        league = League(name='league',
                        owner=user,
                        created_date=timezone.now(),
                        signup_code="ehh")
        league.save()
        league.participants.add(user)
        league.save()
        self.league = league

        #second user
        second_user = User.objects.create(username='******')
        second_user.set_password('1234')
        second_user.save()

        #third user
        third_user = User.objects.create(username='******')
        third_user.set_password('1234')
        third_user.save()

        #set up league for new users
        league.participants.add(second_user)
        league.participants.add(third_user)
        league.save()

        #first team with players
        first_team = Team(team_name='jabs',
                          team_owner_id=user.id,
                          created_date=timezone.now(),
                          league=self.league)
        first_team.save()
        self.first_team = first_team

        #second team with players
        second_team = Team(team_name='jabronis',
                           team_owner_id=second_user.id,
                           created_date=timezone.now(),
                           league=self.league)
        second_team.save()
        self.second_team = second_team

        #second team with players
        third_team = Team(team_name='asdf',
                          team_owner_id=third_user.id,
                          created_date=timezone.now(),
                          league=self.league)
        third_team.save()
Exemplo n.º 3
0
 def set_up_league(self):
     league = League(name='league',
                     owner=self.user,
                     created_date=timezone.now(),
                     signup_code="ehh")
     league.save()
     league.participants.add(self.user)
     league.save()
     self.league = league
Exemplo n.º 4
0
    def setUp(self):
        #first user
        first_user = User.objects.create(username='******')
        first_user.set_password('1234')
        first_user.email = '*****@*****.**'
        first_user.save()

        #second user
        second_user = User.objects.create(username='******')
        second_user.set_password('1234')
        second_user.email = '*****@*****.**'
        second_user.save()

        #set up league
        league = League(name='league',
                        owner=first_user,
                        created_date=timezone.now(),
                        signup_code="ehh")
        league.save()
        league.participants.add(first_user)
        league.participants.add(second_user)
        league.save()
        self.league = league

        #first team with players
        first_team = Team(team_name='jabs',
                          team_owner_id=first_user.id,
                          created_date=timezone.now(),
                          league=self.league)
        first_team.save()
        first_player = UserPlayer(player_team=first_team,
                                  player_first_name='joe',
                                  player_last_name='momma',
                                  league=league)
        first_player.save()

        #second team with players
        second_team = Team(team_name='jabronis',
                           team_owner_id=second_user.id,
                           created_date=timezone.now(),
                           league=self.league)
        second_team.save()
        second_player = UserPlayer(player_team=second_team,
                                   player_first_name='joseph',
                                   player_last_name='momma',
                                   league=league)
        second_player.save()

        #make the trade sucka!
        new_trade = Trade(proposing_team=first_team,
                          receiving_team=second_team,
                          created_date=timezone.now())
        new_trade.save()
        new_trade.proposing_team_players.add(first_player)
        new_trade.receiving_team_players.add(second_player)
        new_trade.save()
        self.trade = new_trade
Exemplo n.º 5
0
 def setUp(self):
     user = User(username='******', password='******')
     user.save()
     self.user = user
     league = League(name='league',
                     owner=user,
                     created_date=timezone.now(),
                     signup_code="ehh")
     league.save()
     league.participants.add(user)
     league.save()
     self.league = league
Exemplo n.º 6
0
    def import_league(self, league: League):
        if self.options['leagues'] and league.bhv_id not in self.options[
                'leagues']:
            LOGGER.debug('SKIPPING League: %s (options)', league)
            return

        if league.youth and not self.options['youth']:
            LOGGER.debug('SKIPPING League (youth league): %s', league)
            return

        tree = logic.get_html(league.source_url())

        game_rows = tree.xpath(
            "//table[@class='gametable']/tr[position() > 1]")
        for game_row in game_rows:
            try:
                self.import_game(game_row, league)
            except Exception:
                logging.getLogger('mail').exception("Could not import Game")
Exemplo n.º 7
0
    def import_league(self, league: League):
        if self.options['leagues'] and league.bhv_id not in self.options[
                'leagues']:
            LOGGER.debug('SKIPPING League: %s (options)', league)
            return

        if league.youth and not self.options['youth']:
            LOGGER.debug('SKIPPING League (youth league): %s', league)
            return

        html = http.get_text(league.source_url())
        dom = parsing.html_dom(html)

        game_rows = parsing.parse_game_rows(dom)
        for game_row in game_rows:
            try:
                self.import_game(game_row, league)
            except Exception:
                logging.getLogger('mail').exception("Could not import Game")
Exemplo n.º 8
0
 def setUp(self):
     user = User.objects.create(username='******')
     user.set_password('1234')
     user.email = '*****@*****.**'
     user.save()
     self.new_user = user
     league = League(name='league',
                     owner=user,
                     created_date=timezone.now(),
                     signup_code="ehh")
     league.save()
     league.participants.add(user)
     league.save()
     self.league = league
Exemplo n.º 9
0
 def setUp(self):
     user = User.objects.create(username='******')
     user.set_password('1234')
     user.save()
     self.new_user = user
     self.login_user()
     self.team_index = self.client.get('/cloud_roni/')
     league = League(name='league',
                     owner=user,
                     created_date=timezone.now(),
                     signup_code="ehh")
     league.save()
     league.participants.add(user)
     league.save()
     self.league = league
Exemplo n.º 10
0
 def setUp(self):
     user = User(username='******', password='******')
     user.save()
     self.user = user
     league = League(name='league',
                     owner=user,
                     created_date=timezone.now(),
                     signup_code="ehh")
     league.save()
     league.participants.add(user)
     league.save()
     self.league = league
     team = Team(created_date=timezone.now(),
                 id=1,
                 team_owner=self.user,
                 league=self.league)
     player = UserPlayer(player_team=team, id=1, league=self.league)
     self.team = team
     self.player = player
Exemplo n.º 11
0
 def set_up_endable_league(self):
     for i in range(0, 3):
         user = User.objects.create(username='******' + str(i))
         user.set_password('1234')
         user.email = '*****@*****.**'
         user.save()
     users = User.objects.all()
     league = League(name='endable_league',
                     owner=User.objects.get(username='******'),
                     created_date=timezone.now(),
                     signup_code="ehh")
     league.save()
     for idx, user in enumerate(users):
         league.participants.add(user)
         league.save()
         team = Team(team_name=str(user),
                     created_date=timezone.now(),
                     team_owner=user,
                     team_points=idx,
                     league=league)
         team.save()
Exemplo n.º 12
0
 def test_non_youth(self):
     for abbreviation, name in NON_YOUTH_LEAGUES:
         with self.subTest(abbreviation=abbreviation, name=name):
             self.assertFalse(
                 League.is_youth(abbreviation=abbreviation, name=name))
Exemplo n.º 13
0
 def test_youth(self):
     for abbreviation, name in YOUTH_LEAGUES:
         with self.subTest(abbreviation=abbreviation, name=name):
             self.assertTrue(
                 League.is_youth(abbreviation=abbreviation, name=name))
Exemplo n.º 14
0
def scrape_league(league_link, district, season, options):
    abbreviation = league_link.text
    bhv_id = parsing.parse_league_bhv_id(league_link)

    if bhv_id in BUGGED_LEAGUES:
        LOGGER.debug('SKIPPING League (ignore list): %s %s', bhv_id, abbreviation)
        return

    if options['leagues'] and bhv_id not in options['leagues']:
        LOGGER.debug('SKIPPING League (options): %s %s', bhv_id, abbreviation)
        return

    if abbreviation == 'TEST':
        LOGGER.debug('SKIPPING League (test league): %s %s', bhv_id, abbreviation)
        return

    url = League.build_source_url(bhv_id)
    html = http.get_text(url)
    dom = parsing.html_dom(html)
    name = parsing.parse_league_name(dom)

    irrelevant_league_name_indicators = [
        'Platzierungsrunde',
        'Kreisvergleichsspiele',
        'pokal', 'Pokal', 'Trophy',
        'Vorbereitung', 'F-FS', 'M-FS', 'Quali',
        'Freiwurf', 'Maxi', 'turnier', 'wettbewerb',
        'Test', 'Planung', 'planung',
    ]

    if any(n in name for n in irrelevant_league_name_indicators):
        LOGGER.debug('SKIPPING League (name): %s %s', bhv_id, name)
        return

    team_links = parsing.parse_team_links(dom)
    if not team_links:
        LOGGER.debug('SKIPPING League (no team table): %s %s', bhv_id, name)
        return

    game_rows = parsing.parse_game_rows(dom)
    if not game_rows:
        LOGGER.debug('SKIPPING League (no games): %s %s', bhv_id, name)
        return

    try:
        name = LeagueName.objects.get(bhv_id=bhv_id).name
    except LeagueName.DoesNotExist:
        pass

    if League.is_youth(abbreviation, name) and not options['youth']:
        LOGGER.debug('SKIPPING League (youth league): %s %s %s', bhv_id, abbreviation, name)
        return

    league, league_created = League.objects.get_or_create(
        name=name, abbreviation=abbreviation, district=district, season=season, bhv_id=bhv_id)
    if league_created:
        LOGGER.info('CREATED League: %s', league)
    else:
        LOGGER.info('EXISTING League: %s', league)

    if options['skip_teams']:
        return

    for team_link in team_links:
        scrape_team(team_link, league)

    retirements = parsing.parse_retirements(dom)
    Team.check_retirements(retirements, league, LOGGER)
Exemplo n.º 15
0
    def create_league(self, league_link, district, season):
        abbreviation = league_link.text
        bhv_id = parsing.parse_league_bhv_id(league_link)

        if self.options['leagues'] and bhv_id not in self.options['leagues']:
            LOGGER.debug('SKIPPING League (options): %s %s', bhv_id,
                         abbreviation)
            return

        if abbreviation == 'TEST':
            LOGGER.debug('SKIPPING League (test league): %s %s', bhv_id,
                         abbreviation)
            return

        url = League.build_source_url(bhv_id)
        dom = logic.get_html(url)
        name = parsing.parse_league_name(dom)

        if any(n in name for n in [
                'Platzierungsrunde', 'Meister', 'Freiwurf', 'Maxi', 'turnier',
                'wettbewerb', 'pokal', 'Test'
        ]):
            LOGGER.debug('SKIPPING League (name): %s %s', bhv_id, name)
            return

        team_links = parsing.parse_team_links(dom)
        if not team_links:
            LOGGER.debug('SKIPPING League (no team table): %s %s', bhv_id,
                         name)
            return

        game_rows = parsing.parse_game_rows(dom)
        if not game_rows:
            LOGGER.debug('SKIPPING League (no games): %s %s', bhv_id, name)
            return

        if len(game_rows) < len(team_links) * (len(team_links) - 1):
            LOGGER.debug('SKIPPING League (few games): %s %s', bhv_id,
                         abbreviation)
            return

        name = {
            5380: "Männer Kreisliga 2-1",
            5381: "Männer Kreisliga 2-2",
            7424: "Männer Kreisliga C Staffel 3",
            50351: "gemischte Jugend D Kreisliga A Staffel 1",
            52853: "männliche Jugend C Bezirksliga Staffel 2",
            58111: "Frauen Oberliga Rheinland-Pfalz/Saar 1",
            58116: "Frauen Oberliga Rheinland-Pfalz/Saar 2",
        }.get(bhv_id, name)

        if League.is_youth(abbreviation, name) and not self.options['youth']:
            LOGGER.debug('SKIPPING League (youth league): %s %s %s', bhv_id,
                         abbreviation, name)
            return

        league, league_created = League.objects.get_or_create(
            name=name,
            abbreviation=abbreviation,
            district=district,
            season=season,
            bhv_id=bhv_id)
        if league_created:
            LOGGER.info('CREATED League: %s', league)
        else:
            LOGGER.info('EXISTING League: %s', league)

        if self.options['skip_teams']:
            return

        for team_link in team_links:
            create_team(team_link, league)

        retirements = parsing.parse_retirements(dom)
        check_retirements(retirements, league)