import os | |
import sqlite3 | |
DATA_DIR = "/data" | |
DB_PATH = os.path.join(DATA_DIR, "data.db") | |
def get_db_connection(): | |
return sqlite3.connect(DB_PATH) | |
def initialize_data_storage(): | |
with get_db_connection() as con: | |
cur = con.cursor() | |
cur.execute("CREATE TABLE IF NOT EXISTS user_rosters( user_id INTEGER, position_id TEXT, player_id TEXT)") | |
def update_selection(user_id: str, position_id: str, player_id: str): | |
with get_db_connection() as con: | |
cur = con.cursor() | |
cur.execute( | |
f"""REPLACE INTO user_rosters (user_id, position_id, player_id ) | |
VALUES({user_id}, '{position_id}', '{player_id}') | |
""" | |
) | |
def get_user_team(user_id): | |
with get_db_connection() as con: | |
cur = con.cursor() | |
cur = get_db_connection().cursor() | |
team = cur.execute(f"select * from user_rosters where user_id = {user_id}").fetchall() | |
if team: | |
return {x[1]: x[2] for x in team} | |
else: | |
return {} | |