def get(self, *a): start, end = daterange(a) games = [] while start <= end: for game in Scraper.game_data(start): games.append(Game.from_scoreboard_data(game)) start += timedelta(days=1) for stat in CachedStats.all(): stat.delete()
def scrape(self): scrape_date = datetime.now() # Scrape yesterday's games up until 10am Central # Dates/times are UTC, which is 5 hours ahead of Central if scrape_date.hour < 15: scrape_date -= timedelta(days=1) for game in Scraper.game_data(scrape_date): Game.from_scoreboard_data(game) for stat in CachedStats.all(): stat.delete()
game_dates = [] if len(sys.argv) > 1: date_str = sys.argv[1] if date_str == "yesterday": game_dates.append(date.today() - timedelta(days=1)) elif date_str == "week": dte = date.today() cur_day = dte.weekday() if cur_day == 0: # If today is Monday, assume we want last week's stats dte -= timedelta(days=1) cur_day = dte.weekday() while cur_day >= 0: game_dates.append(dte) dte -= timedelta(days=1) cur_day -= 1 else: game_dates.append(datetime.strptime(date_str, "%Y%m%d")) if len(game_dates) == 0: game_dates.append(date.today()) league = LeagueStats() for game_date in game_dates: for game in Scraper.game_data(game_date): for team in game_stats(game): league.add_stats(team) print league