51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
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:
|
|
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
|
|
|
|
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() |