Guest User

Untitled

a guest
Apr 12th, 2022
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.58 KB | None | 0 0
  1. import sqlite3
  2.  
  3. def create_database(db_path):
  4.     con = sqlite3.connect(db_path)
  5.     cur = con.cursor()
  6.     cur.execute('''CREATE TABLE players
  7.                   (id integer PRIMARY KEY,
  8.                    pid text,
  9.                    team_id integer,
  10.                    name text,
  11.                    country integer,
  12.                    age integer,
  13.                    height integer,
  14.                    weight integer,
  15.                    value integer,
  16.                    value_adjusted integer,
  17.                    wage integer,
  18.                    form integer,
  19.                    goals integer,
  20.                    assists integer,
  21.                    matches integer,
  22.                    nt_goals integer,
  23.                    nt_assists integer,
  24.                    nt_matches integer,
  25.                    nt_status integer,
  26.                    exp integer,
  27.                    tw integer,
  28.                    disc integer,
  29.                    best_note integer,
  30.                    main_order text,
  31.                    best_note_order text,
  32.                    avg_note integer,
  33.                    all_notes text,
  34.                    all_orders text,
  35.                    match_ids text
  36.                   )''')
  37.     con.commit()
  38.  
  39. def add_players_to_db(players, db_path):
  40.     con = sqlite3.connect(db_path)
  41.     cur = con.cursor()
  42.     for key, val in sorted(players.items()):
  43.         all_notes = list_to_str(val['all_notes'])
  44.         all_orders = list_to_str(val['all_orders'], is_orders = True)
  45.         match_ids = list_to_str(val['match_ids'])
  46.         query = '''INSERT INTO players (pid, team_id, name, country, age, height, weight, value, value_adjusted,
  47.                   wage, form, goals, assists, matches, nt_goals, nt_assists, nt_matches, nt_status, exp, tw, disc,
  48.                   best_note, main_order, avg_note, best_note_order, all_notes, all_orders, match_ids)
  49.                   VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'''
  50.         cur.execute(query, (key, val['team_id'], val['name'], val['country'], val['age'], val['height'],
  51.                             val['weight'], val['value'], val['value_adjusted'], val['wage'], val['form'],
  52.                             val['goals'], val['assists'], val['matches'], val['nt_goals'], val['nt_assists'],
  53.                             val['nt_matches'], val['nt_status'], val['exp'], val['tw'], val['disc'], val['best_note'], val['main_order'],
  54.                             val['avg_note'], val['best_note_order'], all_notes, all_orders, match_ids))
  55.     con.commit()
Advertisement
Add Comment
Please, Sign In to add comment