Added agents
This commit is contained in:
57
agents.py
Normal file
57
agents.py
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import psycopg2, json
|
||||||
|
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS agents (
|
||||||
|
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
|
||||||
|
rarity uuid REFERENCES rarity(id) NOT NULL,
|
||||||
|
name varchar NOT NULL,
|
||||||
|
display varchar NOT NULL,
|
||||||
|
def_index integer NOT NULL,
|
||||||
|
team integer NOT NULL, -- 0 = CT, 1 = T, 2 = BOTH
|
||||||
|
model_player varchar NOT NULl
|
||||||
|
);
|
||||||
|
"""
|
||||||
|
|
||||||
|
conn = psycopg2.connect("dbname=porning user=aindustries")
|
||||||
|
cur = conn.cursor()
|
||||||
|
|
||||||
|
cur.execute("SELECT * FROM rarity")
|
||||||
|
raw_rarity = cur.fetchall()
|
||||||
|
rarity = {rarity[1]: rarity[0] for rarity in raw_rarity}
|
||||||
|
|
||||||
|
with open("agents.json", "r") as f:
|
||||||
|
content = json.load(f)
|
||||||
|
|
||||||
|
agents = {}
|
||||||
|
|
||||||
|
for raw in content:
|
||||||
|
if raw["id"] in agents:
|
||||||
|
continue
|
||||||
|
|
||||||
|
team = raw["team"]["id"]
|
||||||
|
|
||||||
|
if team == "counter-terrorists":
|
||||||
|
team = 0
|
||||||
|
elif team == "terrorists":
|
||||||
|
team = 1
|
||||||
|
else:
|
||||||
|
team = 2
|
||||||
|
|
||||||
|
agent = {
|
||||||
|
"name": raw["id"],
|
||||||
|
"display": raw["name"],
|
||||||
|
"def_index": raw["def_index"],
|
||||||
|
"team": team,
|
||||||
|
"model_player": raw["model_player"],
|
||||||
|
"rarity": rarity[raw["rarity"]["name"]]
|
||||||
|
}
|
||||||
|
|
||||||
|
agents[agent["name"]] = agent
|
||||||
|
|
||||||
|
for agent in agents.values():
|
||||||
|
cur.execute("INSERT INTO agents (name, display, def_index, team, model_player, rarity) VALUES (%s, %s, %s, %s, %s, %s)", (agent["name"], agent["display"], agent["def_index"], agent["team"], agent["model_player"], agent["rarity"]))
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
cur.close()
|
||||||
|
conn.close()
|
||||||
Reference in New Issue
Block a user