def main(): if constants.current_week < 0 or constants.current_week > 17: print('ERROR: Invalid current week: %d' % constants.current_week) return print("Initializing") init() leagues = OrderedDict() for league_tuple in constants.league_definitions: print("Processing %s league" % league_tuple[1]) leagues[league_tuple[0]] = League(league_tuple[0], league_tuple[1]) leagues[league_tuple[0]] = parse_league_html(leagues[league_tuple[0]], constants.current_week) pickle_json_to_file(constants.league_week_storage_path_template % (constants.current_week, league_tuple[0]), leagues[league_tuple[0]]) print("Extracting Pro data") pro_league_data = extract_pro_data(leagues[constants.pro_league_id], constants.current_week) if 0 < constants.current_week < 17: print("Parsing NFL data") nfl_week_data = parse_nfl_html(get_nfl_html(constants.current_week)) else: nfl_week_data = {} print("Writing weekly output") write_output(leagues, constants.current_week, pro_league_data, nfl_week_data)
def main(): if constants.current_week < 0 or constants.current_week > 17: print('ERROR: Invalid current week: %d' % constants.current_week) return print("Initializing") init() leagues = OrderedDict() for league_tuple in constants.league_definitions: print("Processing %s league" % league_tuple[1]) leagues[league_tuple[0]] = League(league_tuple[0], league_tuple[1]) leagues[league_tuple[0]] = parse_league_html(leagues[league_tuple[0]], constants.current_week) pickle_json_to_file(constants.league_week_storage_path_template % (constants.current_week, league_tuple[0]), leagues[league_tuple[0]]) print("Extracting Pro data") pro_league_data = extract_pro_data(leagues[constants.pro_league_id], constants.current_week) if 0 < constants.current_week < 17: print("Parsing NFL data") nfl_week_data = parse_nfl_html(get_nfl_html(constants.current_week)) else: nfl_week_data = {} print("Writing weekly output") write_output(leagues, constants.current_week, pro_league_data, nfl_week_data) if constants.current_week > 1: keeper_file = constants.keeper_week_storage_path_template % constants.current_week if os.path.exists(keeper_file): print("We already processed keepers for week %d" % constants.current_week) else: keeper = None for league_id in leagues: if leagues[league_id].name == 'Keeper': keeper = leagues[league_id] break if keeper is None: print('ERROR: Keeper league not found.') else: print("Processing Keeper data") keeper_league = get_keeper_prices(keeper) print("Writing Keeper data") write_keeper(keeper_league) print("Checkpointing Keeper data") pickle_json_to_file(keeper_file, keeper_league)
def extract_pro_data(pro_league, current_week): pro_data = unpickle_json_from_file(constants.pro_data_storage_path) pro_data = pro_data if pro_data is not None else {} # print(pro_data) i = 0 max_pf = -1 for team_id in pro_league.teams: if current_week <= 14: if pro_league.teams[team_id].div_rank == 1: i += 1 division_ref = 'div%s' % i award = gwjffl.Award('Division Winner') # TODO: constant award.value = 15 # TODO: externalize award.team = pro_league.teams[team_id] pro_data[division_ref] = award if pro_league.teams[team_id].rank == 1: award = gwjffl.Award('#1 Overall') # TODO: constant award.value = 10 # TODO: externalize award.team = pro_league.teams[team_id] pro_data['number_one'] = award if pro_league.teams[team_id].points_for > max_pf: max_pf = pro_league.teams[team_id].points_for if 'regular_season_most_points' not in pro_data: pro_data['regular_season_most_points'] = {} award = gwjffl.Award('Most total points') # TODO: constant award.value = 25 # TODO: externalize award.team = pro_league.teams[team_id] award.points = pro_league.teams[team_id].points_for pro_data['regular_season_most_points'] = award elif current_week == 17: if pro_league.teams[team_id].rank == 1: award = gwjffl.Award('1st place') # TODO: constant award.value = 100 # TODO: externalize award.team = pro_league.teams[team_id] pro_data['first'] = award if pro_league.teams[team_id].rank == 2: award = gwjffl.Award('2nd place') # TODO: constant award.value = 50 # TODO: externalize award.team = pro_league.teams[team_id] pro_data['second'] = award if pro_league.teams[team_id].rank == 3: award = gwjffl.Award('3rd place') # TODO: constant award.value = 25 # TODO: externalize award.team = pro_league.teams[team_id] pro_data['third'] = award if current_week == 17: award = gwjffl.Award('Consolation Champ') # TODO: constant award.value = 15 # TODO: externalize award.team = get_consolation_winner(pro_league, current_week) pro_data['consolation_champ'] = award award = gwjffl.Award('Highest single-week team total') if current_week <= 14: highest_score = 'regular_season_highest_score' # TODO: constant award.value = 10 # TODO: externalize else: highest_score = 'postseason_highest_score' # TODO: constant award.value = 5 # TODO: externalize if pro_data.get(highest_score, None) is None: pro_data[highest_score] = award for result in pro_league.scores: if result.score > pro_data[highest_score].points: pro_data[highest_score].points = result.score pro_data[highest_score].team = pro_league.teams[result.team_id] pro_data[highest_score].week = current_week - 1 pickle_json_to_file(constants.pro_data_storage_path, pro_data) return pro_data