File size: 1,018 Bytes
560823b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 {}