예제 #1
0
    def test_parse(self):
        print('test_parse')

        test_parse_item = BoxscoreParser.parse(
            self=BoxscoreParser, boxscore_xml=self.boxscore_xml_sel)
        test_score_table_item = test_parse_item[0]
        test_boxscore_item = test_parse_item[1]
        test_boxscore_stats_item = test_parse_item[2]

        # Method testing the score table item
        self.assertEqual(test_score_table_item, MOCK_SCORE_TABLE_DICT)

        # Methods testing the boxscore_item
        self.assertEqual(test_boxscore_item['match_id'], 101245565)
        self.assertEqual(test_boxscore_item['match_type'], 'league.rs')
        self.assertEqual(test_boxscore_item['away_off_strategy'], 'RunAndGun')
        self.assertEqual(test_boxscore_item['home_off_strategy'], 'Patient')
        self.assertEqual(test_boxscore_item['away_def_strategy'], 'ManToMan')
        self.assertEqual(test_boxscore_item['away_prep_focus'], 'Inside')
        self.assertEqual(test_boxscore_item['away_prep_focus_matched'], 'miss')
        self.assertEqual(test_boxscore_item['away_prep_pace'], None)
        self.assertEqual(test_boxscore_item['away_prep_pace_matched'], None)
        self.assertEqual(test_boxscore_item['home_def_strategy'], '23Zone')
        self.assertEqual(test_boxscore_item['home_prep_pace'], 'Fast')
        self.assertEqual(test_boxscore_item['home_prep_pace_matched'], 'hit')

        # Methods testing team ratings
        # Away team tests
        self.assertEqual(test_boxscore_item['away_outside_off'], 7.6)
        self.assertEqual(test_boxscore_item['away_inside_off'], 6)
        self.assertEqual(test_boxscore_item['away_outside_def'], 5.6)
        self.assertEqual(test_boxscore_item['away_inside_def'], 7.3)
        self.assertEqual(test_boxscore_item['away_reb'], 5.3)
        self.assertEqual(test_boxscore_item['away_off_flow'], 5)
        # Home team tests
        self.assertEqual(test_boxscore_item['home_outside_off'], 6.6)
        self.assertEqual(test_boxscore_item['home_inside_off'], 7)
        self.assertEqual(test_boxscore_item['home_outside_def'], 5.6)
        self.assertEqual(test_boxscore_item['home_inside_def'], 9.3)
        self.assertEqual(test_boxscore_item['home_reb'], 7.6)
        self.assertEqual(test_boxscore_item['home_off_flow'], 5.6)

        # Methods testing get_stats
        for player in test_boxscore_stats_item:
            if player['player_id'] == 28668697:
                for field in player:
                    print('field: ', field)
                    self.assertEqual(player[field],
                                     MOCK_BOXSCORE_STATS_DICT[field])
예제 #2
0
    def parse_boxscore(self, response):
        boxscore_xml = response.xpath('//bbapi/match')
        match_id = response.meta['match_id']

        try:
            bs_all_items = BoxscoreParser.parse(self=BoxscoreParser,
                                                boxscore_xml=boxscore_xml)
        except TypeError:
            self.logger.error('Re-login for match ' + str(match_id))
            scrapy.Request(url=self.API_URL)
            yield response.follow(url=response.url,
                                  callback=self.parse_boxscore,
                                  meta={'match_id': match_id})
        else:
            score_table_items = bs_all_items[0]
            boxscore_item = bs_all_items[1]
            boxscore_stats_items = bs_all_items[2]
            team_items = bs_all_items[3]

            for team_item in team_items:
                yield team_item

            for score_table_item in score_table_items:
                yield score_table_items[score_table_item]

            yield boxscore_item

            for boxscore_stats_item in boxscore_stats_items:

                if self.parse_players:
                    player_id = boxscore_stats_item['player_id']
                    url = 'http://www.buzzerbeater.com/player/' \
                          + str(player_id) \
                          + '/overview.aspx'
                    yield response.follow(url=url, callback=self.parse_player)

                yield boxscore_stats_item

            # Following the link to Play-By-Play page
            if self.parse_pbps:
                pbp_link = 'http://www.buzzerbeater.com/match/' \
                           + str(match_id) \
                           + '/pbp.aspx'

                yield response.follow(url=pbp_link, callback=self.parse_pbp)