Example #1
0
def get_worst_year(player_id):

    obj = {}

    query = f'SELECT MIN(points) AS points, season FROM players_all_time WHERE player_id={player_id} AND season != 2020 GROUP BY player_id'

    print(query)

    row = get_row(query)

    if row:
        obj["points"] = row["points"]
        obj["season"] = row["season"]

        return obj

    query = f'SELECT MIN(points) AS points, season FROM players_all_time WHERE player_id={player_id} GROUP BY player_id'

    print(query)

    row = get_row(query)

    if row:
        obj["points"] = row["points"]
        obj["season"] = row["season"]

        return obj

    obj["points"] = "N/A"
    obj["season"] = "-"

    return obj
def get_trades(season):

    query = f'SELECT * FROM trades_detail WHERE season = {season} AND owner_id != 63 ORDER BY stamp DESC'

    trades = get_rows(query)

    for x in range(0, len(trades)):

        added_id = trades[x]['added_player_id']

        dropped_id = trades[x]['dropped_player_id']

        query = f'SELECT fnf FROM players WHERE player_id = {added_id}'

        r = get_row(query)

        trades[x]['added_fnf'] = r['fnf']

        query = f'SELECT fnf FROM players WHERE player_id = {dropped_id}'

        r = get_row(query)

        trades[x]['dropped_fnf'] = r['fnf']

        d = trades[x]['stamp'].strftime('%b %-d')

        trades[x]['date'] = trades[x]['stamp'].strftime('%b %-d')

        query = f'SELECT pos FROM playersXseasons WHERE player_id = {dropped_id}'

        r = get_row(query)

        trades[x]['pos'] = r['pos']

    return trades
Example #3
0
def get_player_content(connection, season, s3, push_to_s3, create_local_files,
                       player_id):

    query = f'SELECT * FROM players_view WHERE player_id={player_id}'

    print(query)

    player = get_row(query)

    if not player:

        rookie_year = get_rookie_year(player_id, season)

        print("the rookie year is: " + str(rookie_year))

        query = f'SELECT fnf FROM players WHERE player_id={player_id}'

        print(query)

        row = get_row(query)

        player = {
            "fnf": row["fnf"],
            "most_points": "N/A",
            "most_points_year": "-",
            "rookie_year": rookie_year
        }

    worst_year = get_worst_year(player_id)

    player["least_points"] = worst_year["points"]

    player["least_points_year"] = worst_year["season"]

    player["all_time_rows"] = get_all_time_rows(connection, player_id)

    player["most_often_drafted_by"] = get_most_drafted_by(
        connection, player_id)

    player["most_recent_appearance"] = get_most_recent_appearance(
        connection, player_id)

    ##################

    with open("html/templates/base.html") as file:
        html = file.read()
        html = html.replace("{page_generated}", str(datetime.datetime.now()))
        html = html.replace("{title}", "Baseball: " + player["fnf"])

    with open("html/templates/player.html") as file:
        player_html = file.read()
        html = html.replace("{main}", player_html)

    for val in player:
        html = html.replace("{" + val + "}", str(player[val]))

    return html
Example #4
0
def get_most_recent_appearance(connection, player_id):

    query = f'SELECT season FROM players_current WHERE player_id={player_id}'

    player = get_row(query)

    if player["season"]:
        return player["season"]

    query = f'SELECT MAX(season) AS season FROM players_all_time WHERE player_id={player_id}'

    player = get_row(query)

    return player["season"]
def get_teams(season):

    query = f'SELECT DISTINCT owner_id FROM ownersXseasons_detail WHERE season = {season} AND owner_id != 63 ORDER BY nickname ASC'

    rows = get_rows(query)

    teams = []

    for row in rows:

        print(row)

        owner_id = row['owner_id']

        query = f'SELECT bank, nickname, owner_id, place, points, recent, salary, season, team_name, yesterday FROM ownersXseasons_detail WHERE owner_id = {owner_id} AND season = {season}'

        team = get_row(query)

        team['place'] = make_ordinal(team['place'])

        team['active_players'] = get_roster(owner_id, season, "active")

        benched_players = get_roster(owner_id, season, "benched")

        if (len(benched_players)) > 0:
            team['has_benched_players'] = True

            team['benched_players'] = benched_players

        teams.append(team)

    return teams
def get_last_updated():

    query = f'SELECT update_desc FROM updates ORDER BY time_of_update DESC LIMIT 1'

    row = get_row(query)

    return row['update_desc']
def get_last_updated(connection, season):

    query = "SELECT update_desc FROM updates ORDER BY time_of_update DESC LIMIT 1"

    print(query)

    row = get_row(query)

    return row["update_desc"]
Example #8
0
def get_rookie_year(player_id, season):

    query = f'SELECT rookie_year FROM players_rookie_year WHERE player_id={player_id}'

    print(query)

    row = get_row(query)

    if row:
        return row["rookie_year"]

    query = f'SELECT year_added FROM players WHERE player_id={player_id}'

    print(query)

    row = get_row(query)

    return row["year_added"]

    print("could not find a rookie year for this player.")

    exit()
Example #9
0
def get_trades_content(connection, season):

	content = {
		"season": season,
		"page_generated": datetime.datetime.now()
	}

	query = f'SELECT * FROM trades_view WHERE season={season} ORDER BY stamp DESC'

	print(query)

	rows = get_rows(query)

	with open("html/templates/trade_row.html") as file:
		template = file.read()

	vals = ["added_player_fnf", "date", "dropped_player_fnf", "nickname", "pos"]

	table_rows = ""

	for row in rows:

		trade_row = template

		added_player_id = row["added_player_id"]
		dropped_player_id = row["dropped_player_id"]

		query = f'SELECT * FROM players_current_view WHERE player_id = {added_player_id}'

		r = get_row(query)

		row["added_player_fnf"] = r["fnf"]

		row["pos"] = r["pos"]

		query = f'SELECT * FROM players WHERE player_id = {dropped_player_id}'

		r = get_row(query)

		row["dropped_player_fnf"] = r["fnf"]

		m = row["stamp"].strftime("%b")
		d = row["stamp"].strftime("%d")

		row["date"] = m + " " + d

		for val in vals:

			trade_row = trade_row.replace("{" + val + "}", row[val])

		table_rows += trade_row

	with open("html/templates/trade_table.html") as file:
		template = file.read()

	###################################################

	template = template.replace("{trades}", table_rows)

	with open("html/templates/base.html") as file:
		base = file.read()

	base = base.replace("{title}", f'Baseball {season}: Trades')

	base = base.replace("{page_generated}", str(content["page_generated"]))

	base = base.replace("{main}", template)

	base = base.replace("{season}", str(season))

	return base