def range_models(self, range_start, range_end, model_name='default', insert_db=False): ''' Gets list of player models for day Args: range_start (str): in %Y-%m-%d format range_end (str): in %Y-%m-%d format model_name (str): default, cash, etc. fn (str): name of model json file to load from disk insert_db (bool): true if want to insert models into database Returns: players (list): parsed model pp_players (list): parsed model, prepared for insert into database Examples: a = FantasyLabsNBAAgent() models = a.range_models(range_start='2016-03-01', range_end='2016-03-07') models = a.range_models(range_start='2016-03-01', range_end='2016-03-07', model_name='phan') models = a.range_models(range_start='2016-03-01', range_end='2016-03-07', model_name='phan', insert_db=True) ''' players = [] pp_players = [] for d in date_list(range_end, range_start): d_players, d_pp_players = self.past_day_models(model_day=dt.datetime.strftime(d, '%Y-%m-%d'), model_name=model_name) players += d_players pp_players += d_pp_players if self.db and insert_db: self.db.insert_salaries(pp_players) return players, pp_players
def scoreboards(self, season_start, season_end): ''' Downloads and parses range of scoreboards Arguments: season_start (str): in %Y-%m-%d format season_end (str): in %Y-%m-%d format Returns: scoreboards (list): scoreboard dicts Examples: a = NBAComAgent() sb = a.scoreboards(season_start='2015-10-27', season_end='2016-04-15') ''' scoreboards = [] for day in reversed(date_list(season_end, season_start)): game_date = dt.datetime.strftime(day, '%Y-%m-%d') scoreboard_json = self.scraper.scoreboard(game_date=game_date) scoreboard = self.parser.scoreboard(scoreboard_json, game_date=game_date) scoreboards.append(scoreboard) if self.insert_db: self.db.insert_scoreboards(scoreboards) return scoreboards
def many_models(self, model_name='default', range_start=None, range_end=None, all_missing=False): ''' TODO: is not implemented Gets list of player models for day Args: range_start (str): in %Y-%m-%d format range_end (str): in %Y-%m-%d format model_name (str): default, cash, etc. Returns: players (list): parsed model Examples: a = FantasyLabsNBAAgent() models = a.many_models(range_start='2016-03-01', range_end='2016-03-07') models = a.many_models(all_missing=True) ''' models = [] if all_missing: for d in self.db.select_list(missing_models()): daystr = datetostr(d, 'fl') models.append({ 'game_date': daystr, 'data': self.one_model(model_day=daystr, model_name=model_name), 'model_name': model_name }) else: for d in date_list(range_end, range_start): daystr = datetostr(d, 'fl') models.append({ 'game_date': daystr, 'data': self.one_model(model_day=daystr, model_name=model_name), 'model_name': model_name }) if self.insert_db: self.db.insert_models(models) return models
def rotoworld(scraper, season, db): results = [] p = RotoworldNBAParser() url = 'http://www.rotoworld.com/teams/depth-charts/nba.aspx' for d in date_list(d2=season_start(season), d1=season_end(season), delta=7): dstr = datetostr(d, 'db') try: content, content_date = scraper.get_wayback(url, d=dstr, max_delta=10) if content and content_date: for r in p.depth_charts(content, dstr): r.pop('pf', None) db._insert_dict(r, 'depth_charts') results.append(r) logging.info('completed {}'.format(dstr)) else: logging.error('could not get {}'.format(dstr)) except Exception as e: logging.exception('could not get {}: {}'.format(dstr, e))