Exemple #1
0
    def test_output_json_when_output_write_option_is_none_and_custom_options(
        self,
        mock_json_writer,
    ):
        mock_json_writer_instance = mock.Mock(write=mock.Mock())
        mock_json_writer.return_value = mock_json_writer_instance

        output(
            values=self.values,
            output_type=OutputType.JSON,
            output_file_path=self.output_file_path,
            csv_writer=None,
            json_options={
                "jae": "baebae",
                "bae": "jadley",
            },
        )

        mock_json_writer.assert_called_once_with(
            encoder=BasketballReferenceJSONEncoder)
        mock_json_writer_instance.write.assert_called_once_with(
            data=self.values,
            options=WriteOptions(
                file_path=self.output_file_path,
                mode=OutputWriteOption.WRITE,
                custom_options={
                    "jae": "baebae",
                    "bae": "jadley",
                },
            ))
Exemple #2
0
def regular_season_player_box_scores(player_identifier,
                                     season_end_year,
                                     output_type=None,
                                     output_file_path=None,
                                     output_write_option=None,
                                     json_options=None):

    try:
        http_service = HTTPService(parser=ParserService())
        values = http_service.regular_season_player_box_scores(
            player_identifier=player_identifier,
            season_end_year=season_end_year,
        )
    except requests.exceptions.HTTPError as http_error:
        if http_error.response.status_code == requests.codes.internal_server_error \
                or http_error.response.status_code == requests.codes.not_found:
            raise InvalidPlayerAndSeason(player_identifier=player_identifier,
                                         season_end_year=season_end_year)
        else:
            raise http_error
    return output(
        values=values,
        output_type=output_type,
        output_file_path=output_file_path,
        output_write_option=output_write_option,
        csv_writer=CSVWriter(
            column_names=PLAYER_SEASON_BOX_SCORE_COLUMN_NAMES,
            row_formatter=RowFormatter(
                data_field_names=PLAYER_SEASON_BOX_SCORE_COLUMN_NAMES)),
        json_options=json_options,
    )
Exemple #3
0
def play_by_play(home_team,
                 day,
                 month,
                 year,
                 output_type=None,
                 output_file_path=None,
                 output_write_option=None,
                 json_options=None):
    try:
        values = http_client.play_by_play(home_team=home_team,
                                          day=day,
                                          month=month,
                                          year=year)
    except requests.exceptions.HTTPError as http_error:
        if http_error.response.status_code == requests.codes.not_found:
            raise InvalidDate(day=day, month=month, year=year)
        else:
            raise http_error
    return output(
        values=values,
        output_type=output_type,
        output_file_path=output_file_path,
        output_write_option=output_write_option,
        csv_writer=CSVWriter(column_names=PLAY_BY_PLAY_COLUMN_NAMES,
                             row_formatter=RowFormatter(
                                 data_field_names=PLAY_BY_PLAY_COLUMN_NAMES)),
        json_options=json_options,
    )
Exemple #4
0
def player_box_scores(day,
                      month,
                      year,
                      output_type=None,
                      output_file_path=None,
                      output_write_option=None,
                      json_options=None):
    try:
        http_service = HTTPService(parser=ParserService())
        values = http_service.player_box_scores(day=day,
                                                month=month,
                                                year=year)
    except requests.exceptions.HTTPError as http_error:
        if http_error.response.status_code == requests.codes.not_found:
            raise InvalidDate(day=day, month=month, year=year)
        else:
            raise http_error
    return output(
        values=values,
        output_type=output_type,
        output_file_path=output_file_path,
        output_write_option=output_write_option,
        csv_writer=CSVWriter(column_names=BOX_SCORE_COLUMN_NAMES,
                             row_formatter=RowFormatter(
                                 data_field_names=BOX_SCORE_COLUMN_NAMES)),
        json_options=json_options,
    )
Exemple #5
0
def players_advanced_season_totals(season_end_year,
                                   include_combined_values=False,
                                   output_type=None,
                                   output_file_path=None,
                                   output_write_option=None,
                                   json_options=None):
    try:
        values = http_client.players_advanced_season_totals(
            season_end_year, include_combined_values=include_combined_values)
    except requests.exceptions.HTTPError as http_error:
        if http_error.response.status_code == requests.codes.not_found:
            raise InvalidSeason(season_end_year=season_end_year)
        else:
            raise http_error
    return output(
        values=values,
        output_type=output_type,
        output_file_path=output_file_path,
        output_write_option=output_write_option,
        csv_writer=CSVWriter(
            column_names=PLAYER_ADVANCED_SEASON_TOTALS_COLUMN_NAMES,
            row_formatter=RowFormatter(
                data_field_names=PLAYER_ADVANCED_SEASON_TOTALS_COLUMN_NAMES)),
        json_options=json_options,
    )
Exemple #6
0
def players_season_totals(season_end_year,
                          output_type=None,
                          output_file_path=None,
                          output_write_option=None,
                          json_options=None):
    try:
        http_service = HTTPService(parser=ParserService())
        values = http_service.players_season_totals(
            season_end_year=season_end_year)
    except requests.exceptions.HTTPError as http_error:
        if http_error.response.status_code == requests.codes.not_found:
            raise InvalidSeason(season_end_year=season_end_year)
        else:
            raise http_error
    return output(
        values=values,
        output_type=output_type,
        output_file_path=output_file_path,
        output_write_option=output_write_option,
        csv_writer=CSVWriter(
            column_names=PLAYER_SEASON_TOTALS_COLUMN_NAMES,
            row_formatter=RowFormatter(
                data_field_names=PLAYER_SEASON_TOTALS_COLUMN_NAMES)),
        json_options=json_options,
    )
Exemple #7
0
def team_box_scores(day,
                    month,
                    year,
                    adv=False,
                    output_type=None,
                    output_file_path=None,
                    output_write_option=None,
                    json_options=None):
    try:
        values = http_client.team_box_scores(day=day,
                                             month=month,
                                             year=year,
                                             adv=adv)
    except requests.exceptions.HTTPError as http_error:
        if http_error.response.status_code == requests.codes.not_found:
            raise InvalidDate(day=day, month=month, year=year)
        else:
            raise http_error
    return output(
        values=values,
        output_type=output_type,
        output_file_path=output_file_path,
        output_write_option=output_write_option,
        csv_writer=team_box_scores_to_csv,
        encoder=BasketballReferenceJSONEncoder,
        json_options=json_options,
    )
Exemple #8
0
    def test_output_csv_when_output_write_option_is_none_and_no_custom_options(
            self):
        csv_writer = mock.Mock(name="csv_writer", write=mock.Mock())
        output(
            values=self.values,
            output_type=OutputType.CSV,
            output_file_path=self.output_file_path,
            csv_writer=csv_writer,
        )

        csv_writer.write.assert_called_once_with(
            data=self.values,
            options=WriteOptions(
                file_path=self.output_file_path,
                mode=OutputWriteOption.WRITE,
            ),
        )
Exemple #9
0
 def test_return_values_when_output_type_is_none(self):
     self.assertEqual(
         self.values,
         output(
             values=self.values,
             output_type=None,
             output_file_path=self.output_file_path,
             csv_writer=self.csv_writer,
         ),
     )
def player_box_scores(day, month, year, output_type=None, output_file_path=None, output_write_option=None, json_options=None):
    values = http_client.player_box_scores(day=day, month=month, year=year)
    return output(
        values=values,
        output_type=output_type,
        output_file_path=output_file_path,
        output_write_option=output_write_option,
        csv_writer=box_scores_to_csv,
        encoder=BasketballReferenceJSONEncoder,
        json_options=json_options,
    )
def players_season_totals(season_end_year, output_type=None, output_file_path=None, output_write_option=None, json_options=None):
    values = http_client.players_season_totals(season_end_year)
    return output(
        values=values,
        output_type=output_type,
        output_file_path=output_file_path,
        output_write_option=output_write_option,
        csv_writer=players_season_totals_to_csv,
        encoder=BasketballReferenceJSONEncoder,
        json_options=json_options,
    )
Exemple #12
0
    def test_output_json_when_output_write_option_is_append_and_no_custom_options(
        self,
        mock_json_writer,
    ):
        mock_json_writer_instance = mock.Mock(write=mock.Mock())
        mock_json_writer.return_value = mock_json_writer_instance

        output(
            values=self.values,
            output_type=OutputType.JSON,
            output_file_path=self.output_file_path,
            csv_writer=None,
            output_write_option=OutputWriteOption.APPEND,
        )

        mock_json_writer.assert_called_once_with(
            encoder=BasketballReferenceJSONEncoder)
        mock_json_writer_instance.write.assert_called_once_with(
            data=self.values,
            options=WriteOptions(
                file_path=self.output_file_path,
                mode=OutputWriteOption.APPEND,
                custom_options=None,
            ))
def players_season_totals(season_end_year, output_type=None, output_file_path=None, output_write_option=None, json_options=None):
    try:
        values = http_client.players_season_totals(season_end_year)
    except requests.exceptions.HTTPError as http_error:
        if http_error.response.status_code == requests.codes.not_found:
            raise InvalidSeason(season_end_year=season_end_year)
        else:
            raise http_error
    return output(
        values=values,
        output_type=output_type,
        output_file_path=output_file_path,
        output_write_option=output_write_option,
        csv_writer=players_season_totals_to_csv,
        encoder=BasketballReferenceJSONEncoder,
        json_options=json_options,
    )
def season_schedule(season_end_year, output_type=None, output_file_path=None, output_write_option=None, json_options=None):
    try:
        values = http_client.season_schedule(season_end_year)
    except requests.exceptions.HTTPError as http_error:
        # https://github.com/requests/requests/blob/master/requests/status_codes.py#L58
        if http_error.response.status_code == requests.codes.not_found:
            raise InvalidSeason(season_end_year=season_end_year)
        else:
            raise http_error
    return output(
        values=values,
        output_type=output_type,
        output_file_path=output_file_path,
        output_write_option=output_write_option,
        csv_writer=schedule_to_csv,
        encoder=BasketballReferenceJSONEncoder,
        json_options=json_options,
    )
Exemple #15
0
def search(term,
           output_type=None,
           output_file_path=None,
           output_write_option=None,
           json_options=None):
    values = http_client.search(term=term)
    return output(
        values=values,
        output_type=output_type,
        output_file_path=output_file_path,
        output_write_option=output_write_option,
        csv_writer=SearchResultsCSVWriter(
            column_names=SEARCH_RESULTS_COLUMN_NAMES,
            row_formatter=RowFormatter(
                data_field_names=SEARCH_RESULTS_COLUMN_NAMES),
        ),
        json_options=json_options,
    )
Exemple #16
0
def season_schedule(season_end_year,
                    output_type=None,
                    output_file_path=None,
                    output_write_option=None,
                    json_options=None):
    try:
        values = http_client.season_schedule(season_end_year)
    except requests.exceptions.HTTPError as http_error:
        # https://github.com/requests/requests/blob/master/requests/status_codes.py#L58
        if http_error.response.status_code == requests.codes.not_found:
            raise InvalidSeason(season_end_year=season_end_year)
        else:
            raise http_error
    return output(
        values=values,
        output_type=output_type,
        output_file_path=output_file_path,
        output_write_option=output_write_option,
        csv_writer=CSVWriter(column_names=SCHEDULE_COLUMN_NAMES,
                             row_formatter=RowFormatter(
                                 data_field_names=SCHEDULE_COLUMN_NAMES)),
        json_options=json_options,
    )