Exemplo n.º 1
0
def update_matchups(query: Query, league_settings: Sequence[LeagueSetting], year: int):
    """
    Update matchups for the current year.

    :param query: the query object
    :param league_settings: the league settings for the current year
    :param year: the current year
    :return: None
    """
    matchups = set(m for m in query.get_matchups(year=year))
    current_matchups = get_current_matchups(league_settings=league_settings) - matchups

    count = len(current_matchups)
    if count == 0:
        logging.info("No matchups to update")
        return

    logging.info(f"Updating {count} matchup scores")
    query.upsert_matchups(current_matchups)
Exemplo n.º 2
0
def main():
    args = parse_args()
    environment = args.get("environment")
    year = args.get("year")
    week = args.get("week")

    app.config.from_object(util.get_config(environment))
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config['SQLALCHEMY_DATABASE_URI'] = app.config.get("DB_URI")
    db.init_app(app)
    query = Query(db)

    with app.app_context():
        team_ids = set(query.get_distinct_matchup_team_ids(year)[week])
        team_id_to_team_name = query.get_team_id_to_team_name(year)
        matchups = [
            m for m in query.get_matchups(year)
            if m.matchup_id == week and m.team_id in team_ids
        ]
        for m in matchups:
            team_name = team_id_to_team_name.get(m.team_id)
            opponent_name = team_id_to_team_name.get(m.opponent_team_id)
            team_filename = get_filename(year, week, m.team_id)
            generate_recap_template(team_filename, team_name, opponent_name)