Beispiel #1
0
    def setUp(self):
        with mock.patch(
                'recleagueparser.parsetime.datetime.datetime') as mck_dt:
            # TODO mock now instead of using real time (i.e. get this to work)
            date_str = '{0}-08-31 18:22:24.033246'.format(THIS_YEAR)
            mock_now = datetime.datetime.strptime(date_str,
                                                  '%Y-%m-%d %H:%M:%S.%f')
            mck_dt.now.return_value = mock_now
            mck_dt.side_effect = lambda *args, **kw: mock_now

        self.test_date = 'Thu Aug 31'
        self.hour_time = '7:22 PM'

        self.game = Game(self.test_date,
                         self.hour_time,
                         'home',
                         None,
                         'away',
                         None,
                         year=2017)
        self.done_game = Game(self.test_date,
                              self.hour_time,
                              'home',
                              6,
                              'away',
                              5,
                              year=2017)
Beispiel #2
0
    def setUp(self, mocked_resp):
        with mock.patch('recleagueparser.schedules.schedule.datetime.datetime'
                        ) as mck_dt:
            # TODO mock now instead of using real time (i.e. get this to work)
            date_str = '{0}-08-31 18:22:24.033246'.format(THIS_YEAR)
            mock_now = datetime.datetime.strptime(date_str,
                                                  '%Y-%m-%d %H:%M:%S.%f')
            mck_dt.now.return_value = mock_now
            mck_dt.side_effect = lambda *args, **kw: mock_now

        self.mock_now = datetime.datetime.strptime(
            '{0}-08-20 18:22:24.033246'.format(THIS_YEAR),
            '%Y-%m-%d %H:%M:%S.%f')
        self.mock_preseason = datetime.datetime.strptime(
            '{0}-07-20 18:22:24.033246'.format(THIS_YEAR),
            '%Y-%m-%d %H:%M:%S.%f')
        self.mock_postseason = datetime.datetime.strptime(
            '{0}-09-20 18:22:24.033246'.format(THIS_YEAR),
            '%Y-%m-%d %H:%M:%S.%f')
        test_date = 'Thu Aug 31'
        test_time = '6:22 PM'
        hour_before = '5:22 PM'
        hour_after = '7:22 PM'

        self.game_in_an_hour = Game(test_date, hour_after, 'home', None,
                                    'away', None)
        self.game_hour_ago = Game(test_date, hour_before, 'home', 6, 'away', 5)
        self.unplayed_game = Game(test_date, hour_before, 'home', None, 'away',
                                  None)

        self.schedule = PointstreakSchedule(0, 0)
        self.schedule.refresh_schedule = mock.MagicMock()
    def parse_table(self):
        """
        Get a list PoinstreakGames by parsing the raw html retrieved
        from the Poinstreak Team Schedule webpage

        Returns:
            a list of PoinstreakGames in order from first to last
        """
        self._logger.info("Parsing games from Pointstreak Data Table")
        games = []
        if self.html_table:
            prevgame = None
            for game_row in self.html_table.find_all('tr'):
                cells = game_row.find_all('td')
                gamedate = cells[self.columns['gameday']].string
                gametime = cells[self.columns['gametime']].string
                home, hscore = self.parse_team(cells[self.columns['hometeam']])
                away, ascore = self.parse_team(cells[self.columns['awayteam']])
                final = self.is_score_final(None)
                game = Game(gamedate,
                            gametime,
                            home,
                            hscore,
                            away,
                            ascore,
                            prevgame=prevgame,
                            final=final)
                games.append(game)
                prevgame = game
        self._logger.info("Parsed {} games".format(len(games)))
        return games
Beispiel #4
0
    def parse_table(self):
        """
        Get a list PoinstreakGames by parsing the raw html retrieved
        from the Poinstreak Team Schedule webpage

        Returns:
            a list of PoinstreakGames in order from first to last
        """
        self._logger.info("Parsing games from DashPlatform Data Table")
        games = []
        now = datetime.datetime.now()
        if self.html_table:
            prevgame = None
            game_rows = self.html_table.find_all('div',
                                                 {'class': 'list-group-item'})
            for game_row in game_rows:
                # Parse Date
                gamedate_cell = game_row.find('div', {
                    'class': 'event__date'
                }).div.find_all('div')
                cell_date = gamedate_cell[0].text
                cell_time = gamedate_cell[1].text.split(' ', 1)[1]
                structured = '{} {}'.format(cell_date, cell_time)
                parsed = pt.normalize_date(structured,
                                           now.year,
                                           return_type=datetime.datetime)
                gamedate = parsed.strftime(pt.DATE_DESCRIPTOR)
                gametime = parsed.strftime(pt.TIME_DESCRIPTOR)

                # Parse Score
                event_cells = game_row.find('div', {'class': 'event__details'})
                score_cells = event_cells.find_all('div', recursive=False)
                away_cells = score_cells[0].find_all('div')
                home_cells = score_cells[1].find_all('div')

                ascore = away_cells[1].text
                hscore = home_cells[1].text
                ascore = None if ascore == "-" else ascore
                hscore = None if hscore == "-" else hscore

                ateam = away_cells[0].a.text
                hteam = home_cells[0].a.text

                final = self.is_score_final(None)
                game = Game(gamedate,
                            gametime,
                            hteam,
                            hscore,
                            ateam,
                            ascore,
                            prevgame=prevgame,
                            final=final)
                games.append(game)
                prevgame = game
        self._logger.info("Parsed {} Games from Data Table".format(len(games)))
        return games
Beispiel #5
0
 def parse_table(self):
     games = list()
     for x in range(0, 100):
         dt = self.now + datetime.timedelta(days=1)
         game = Game(dt.strftime("%a %b %d"),
                     dt.strftime("%I:%M %p EST"),
                     'home',
                     None,
                     'away',
                     None,
                     year=dt.strftime("%Y"),
                     prevgame=None)
         games.append(game)
     return games
Beispiel #6
0
 def refresh_schedule(self):
     self.refresh_count += 1
     if self.refresh_count % 5 != 0:
         return
     last = self.games[len(self.games) - 1]
     new = last.full_gametime + datetime.timedelta(hours=1)
     self.games.append(
         Game(new.strftime("%a %b %d"),
              new.strftime("%I:%M %p EST"),
              'home',
              None,
              'away',
              None,
              year=new.strftime("%Y"),
              prevgame=None))
Beispiel #7
0
 def parse_table(self):
     games = list()
     game_dts = [
         [self.now - datetime.timedelta(days=366), 3, 2],  # Last Year
         [self.now - datetime.timedelta(days=1), 3, 2],  # Yesterday
         [self.now + datetime.timedelta(hours=1), None, None],  # Today
         [self.now + datetime.timedelta(days=1), None, None],  # Tommorrow
         [self.now + datetime.timedelta(days=366), None, None],  # Next Year
     ]
     for game_dt in game_dts:
         game = Game(game_dt[0].strftime("%a %b %d"),
                     game_dt[0].strftime("%I:%M %p EST"),
                     'home',
                     game_dt[1],
                     'away',
                     game_dt[2],
                     year=game_dt[0].strftime("%Y"),
                     prevgame=None,
                     final=False)
         games.append(game)
     return games
 def parse_table(self):
     self._logger.info("Parsing Games from SportsEngine Data Table")
     games = []
     prevgame = None
     for game_row in self.html_table.find_all('tr'):
         cells = game_row.find_all('td')
         gamedate = cells[self.columns['gameday']].text
         gametime = self.get_game_time(cells[self.columns['gametime']])
         cancelled = self.is_game_cancelled(gametime)
         hometeam, awayteam = self.parse_teams(
             cells[self.columns['awayteam']])
         homescore, awayscore = self.parse_score(
             cells[self.columns['result']],
             cells[self.columns['awayteam']])
         final = self.is_score_final(cells[self.columns['result']])
         game = Game(gamedate, gametime, hometeam, homescore, awayteam,
                     awayscore, prevgame=prevgame, final=final,
                     cancelled=cancelled)
         games.append(game)
         prevgame = game
     self._logger.info("Parsed {} Games from Table".format(len(games)))
     return games