Beispiel #1
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,
    )
Beispiel #2
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,
    )
Beispiel #3
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,
    )
Beispiel #4
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,
    )
Beispiel #5
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,
    )
 def test_header_is_written(self, mock_csv_dict_writer):
     csv_dict_writer = mock.Mock(wrteheader=mock.Mock(),
                                 writerows=mock.Mock())
     mock_csv_dict_writer.return_value = csv_dict_writer
     row_formatter = mock.Mock(format=mock.Mock())
     csv_dict_writer = mock.Mock(wrteheader=mock.Mock(),
                                 writerows=mock.Mock())
     mock_csv_dict_writer.return_value = csv_dict_writer
     writer = CSVWriter(column_names=self.COLUMN_NAMES,
                        row_formatter=row_formatter)
     writer.write(data=self.DATA,
                  options=WriteOptions(file_path="some file path",
                                       mode=OutputWriteOption.WRITE))
     csv_dict_writer.writeheader.assert_called_once_with()
 def test_file_and_columns_are_used_by_writer(self, mock_csv_dict_writer):
     with mock.patch("builtins.open", mock.mock_open()) as mock_file:
         csv_dict_writer = mock.Mock(wrteheader=mock.Mock(),
                                     writerows=mock.Mock())
         mock_csv_dict_writer.return_value = csv_dict_writer
         row_formatter = mock.Mock(format=mock.Mock())
         csv_dict_writer = mock.Mock(wrteheader=mock.Mock(),
                                     writerows=mock.Mock())
         mock_csv_dict_writer.return_value = csv_dict_writer
         writer = CSVWriter(column_names=self.COLUMN_NAMES,
                            row_formatter=row_formatter)
         writer.write(data=self.DATA,
                      options=WriteOptions(file_path="some file path",
                                           mode=OutputWriteOption.WRITE))
         mock_csv_dict_writer.assert_called_with(
             mock_file(), fieldnames=self.COLUMN_NAMES)
 def test_opens_correct_file(self, mock_csv_dict_writer):
     with mock.patch("builtins.open", mock.mock_open()) as mock_file:
         csv_dict_writer = mock.Mock(wrteheader=mock.Mock(),
                                     writerows=mock.Mock())
         mock_csv_dict_writer.return_value = csv_dict_writer
         row_formatter = mock.Mock(format=mock.Mock())
         csv_dict_writer = mock.Mock(wrteheader=mock.Mock(),
                                     writerows=mock.Mock())
         mock_csv_dict_writer.return_value = csv_dict_writer
         writer = CSVWriter(column_names=self.COLUMN_NAMES,
                            row_formatter=row_formatter)
         writer.write(data=self.DATA,
                      options=WriteOptions(file_path="some file path",
                                           mode=OutputWriteOption.WRITE))
         mock_file.assert_called_with("some file path",
                                      OutputWriteOption.WRITE.value,
                                      newline="",
                                      encoding="utf8")
 def test_rows_are_written(self, mock_csv_dict_writer):
     csv_dict_writer = mock.Mock(wrteheader=mock.Mock(),
                                 writerows=mock.Mock())
     mock_csv_dict_writer.return_value = csv_dict_writer
     row_formatter = mock.Mock(format=mock.Mock())
     csv_dict_writer = mock.Mock(wrteheader=mock.Mock(),
                                 writerows=mock.Mock())
     mock_csv_dict_writer.return_value = csv_dict_writer
     writer = CSVWriter(column_names=self.COLUMN_NAMES,
                        row_formatter=row_formatter)
     writer.write(data=self.DATA,
                  options=WriteOptions(file_path="some file path",
                                       mode=OutputWriteOption.WRITE))
     csv_dict_writer.writerows.assert_called_once_with(mock.ANY)
     self.assertEqual(3, row_formatter.format.call_count)
     row_formatter.format.assert_has_calls(calls=[
         mock.call("some"),
         mock.call("row"),
         mock.call("data"),
     ],
                                           any_order=False)
Beispiel #10
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,
    )