import psycopg2, json """ CREATE TABLE IF NOT EXISTS weapons ( id uuid DEFAULT gen_random_uuid() PRIMARY KEY, name varchar NOT NULL, display varchar NOT NULL, def_index integer NOT NULL, category varchar NOT NULL, team integer NOT NULL -- 0 = CT, 1 = T, 2 = BOTH ); """ conn = psycopg2.connect("dbname=porning user=aindustries") cur = conn.cursor() with open("skins.json", "r") as f: content = json.load(f) weapons = {} for raw in content: if raw["weapon"]["id"] in weapons or "sfui_wpnhud" in raw["weapon"]["id"]: continue team = raw["team"]["id"] if team == "counter-terrorists": team = 0 elif team == "terrorists": team = 1 else: team = 2 weapon = { "name": raw["weapon"]["id"], "display": raw["weapon"]["name"], "def_index": raw["weapon"]["weapon_id"], "category": raw["category"]["name"], "team": team } weapons[weapon["name"]] = weapon # Default knives and gloves that are not in the json weapons["weapon_knife_t"] = { "name": "weapon_knife_t", "display": "Knife", "def_index" : 59, "category": "Knives", "team": 1 } weapons["weapon_knife"] = { "name": "weapon_knife", "display": "Knife", "def_index" : 42, "category": "Knives", "team": 0 } weapons["t_gloves"] = { "name": "t_gloves", "display": "Default T Gloves", "def_index" : 5028, "category": "Gloves", "team": 1 } weapons["ct_gloves"] = { "name": "ct_gloves", "display": "Default CT Gloves", "def_index" : 5029, "category": "Gloves", "team": 0 } for weapon in weapons.values(): cur.execute("INSERT INTO weapons (name, display, def_index, category, team) VALUES (%s, %s, %s, %s, %s)", (weapon["name"], weapon["display"], weapon["def_index"], weapon["category"], weapon["team"])) conn.commit() cur.close() conn.close()