Exemplo n.º 1
0
 def test_parse_league_abbreviations_for_multiple_baa_abbreviations(self):
     parsed_player = self.parser.parse(
         player=PlayerData(name="jaebaebae",
                           resource_location='/players/b/bryanko01.html',
                           league_abbreviations=["BAA", "BAA"]))
     self.assertEqual(parsed_player["leagues"],
                      {League.BASKETBALL_ASSOCIATION_OF_AMERICA})
Exemplo n.º 2
0
 def test_parse_league_abbreviations_for_single_aba_abbreviation(self):
     parsed_player = self.parser.parse(
         player=PlayerData(name="jaebaebae",
                           resource_location='/players/b/bryanko01.html',
                           league_abbreviations=["ABA"]))
     self.assertEqual(parsed_player["leagues"],
                      {League.AMERICAN_BASKETBALL_ASSOCIATION})
def search(term):
    response = requests.get(
        url="{BASE_URL}/search/search.fcgi".format(BASE_URL=BASE_URL),
        params={"search": term}
    )

    response.raise_for_status()

    player_results = []

    if response.url.startswith("{BASE_URL}/search/search.fcgi".format(BASE_URL=BASE_URL)):
        page = SearchPage(html=html.fromstring(response.content))

        parser = SearchResultsParser(
            search_result_name_parser=SearchResultNameParser(),
            search_result_location_parser=ResourceLocationParser(
                resource_location_regex=SEARCH_RESULT_RESOURCE_LOCATION_REGEX,
            ),
            league_abbreviation_parser=LeagueAbbreviationParser(
                abbreviations_to_league=LEAGUE_ABBREVIATIONS_TO_LEAGUE,
            ),
        )

        parsed_results = parser.parse(nba_aba_baa_players=page.nba_aba_baa_players)
        player_results += parsed_results["players"]

        while page.nba_aba_baa_players_pagination_url is not None:
            response = requests.get(
                url="{BASE_URL}/search/{pagination_url}".format(
                    BASE_URL=BASE_URL,
                    pagination_url=page.nba_aba_baa_players_pagination_url
                )
            )

            response.raise_for_status()

            page = SearchPage(html=html.fromstring(response.content))

            parsed_results = parser.parse(nba_aba_baa_players=page.nba_aba_baa_players)
            player_results += parsed_results["players"]

    elif response.url.startswith("{BASE_URL}/players".format(BASE_URL=BASE_URL)):
        page = PlayerPage(html=html.fromstring(response.content))
        data = PlayerData(
            name=page.name,
            resource_location=response.url,
            league_abbreviations=set([row.league_abbreviation for row in page.totals_table.rows])
        )
        parser = PlayerDataParser(
            search_result_location_parser=ResourceLocationParser(
                resource_location_regex=SEARCH_RESULT_RESOURCE_LOCATION_REGEX,
            ),
            league_abbreviation_parser=LeagueAbbreviationParser(abbreviations_to_league=LEAGUE_ABBREVIATIONS_TO_LEAGUE),
        )
        player_results += [parser.parse(player=data)]

    return {
        "players": player_results
    }
 def test_instantiation(self):
     data = PlayerData(
         name="some name",
         resource_location="some location",
         league_abbreviations=["NBA", "ABA", "NBA", "ABA"],
     )
     self.assertEqual(data.name, "some name")
     self.assertEqual(data.resource_location, "some location")
     self.assertEqual(data.league_abbreviations, {"NBA", "ABA"})
Exemplo n.º 5
0
    def search(self, term):
        response = requests.get(url="{BASE_URL}/search/search.fcgi".format(
            BASE_URL=HTTPService.BASE_URL),
                                params={"search": term})

        response.raise_for_status()

        player_results = []

        if response.url.startswith("{BASE_URL}/search/search.fcgi".format(
                BASE_URL=HTTPService.BASE_URL)):
            page = SearchPage(html=html.fromstring(response.content))
            parsed_results = self.parser.parse_player_search_results(
                nba_aba_baa_players=page.nba_aba_baa_players)
            player_results += parsed_results["players"]

            while page.nba_aba_baa_players_pagination_url is not None:
                response = requests.get(
                    url="{BASE_URL}/search/{pagination_url}".format(
                        BASE_URL=HTTPService.BASE_URL,
                        pagination_url=page.nba_aba_baa_players_pagination_url)
                )

                response.raise_for_status()

                page = SearchPage(html=html.fromstring(response.content))

                parsed_results = self.parser.parse_player_search_results(
                    nba_aba_baa_players=page.nba_aba_baa_players)
                player_results += parsed_results["players"]

        elif response.url.startswith(
                "{BASE_URL}/players".format(BASE_URL=HTTPService.BASE_URL)):
            page = PlayerPage(html=html.fromstring(response.content))
            data = PlayerData(name=page.name,
                              resource_location=response.url,
                              league_abbreviations=set([
                                  row.league_abbreviation
                                  for row in page.totals_table.rows
                                  if row.league_abbreviation is not None
                              ]))
            player_results += [self.parser.parse_player_data(player=data)]

        return {"players": player_results}
Exemplo n.º 6
0
 def test_parse_resource_location(self):
     parsed_player = self.parser.parse(
         player=PlayerData(name="jaebaebae",
                           resource_location='/players/b/bryanko01.html',
                           league_abbreviations=[]))
     self.assertEqual(parsed_player["identifier"], "bryanko01")