Rarity importer
This commit is contained in:
36
rarity.py
36
rarity.py
@@ -0,0 +1,36 @@
|
||||
import psycopg2, json
|
||||
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS rarity (
|
||||
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
|
||||
display varchar NOT NULL,
|
||||
color varchar NOT NULL
|
||||
);
|
||||
"""
|
||||
|
||||
conn = psycopg2.connect("dbname=porning user=aindustries")
|
||||
cur = conn.cursor()
|
||||
|
||||
with open("skins.json", "r") as f:
|
||||
content = json.load(f)
|
||||
|
||||
rarities = {}
|
||||
|
||||
for raw in content:
|
||||
if raw["rarity"]["name"] in rarities:
|
||||
continue
|
||||
|
||||
rarity = {
|
||||
"display": raw["rarity"]["name"],
|
||||
"color": raw["rarity"]["color"]
|
||||
}
|
||||
|
||||
rarities[rarity["display"]] = rarity
|
||||
|
||||
for rarity in rarities.values():
|
||||
cur.execute("INSERT INTO rarity (display, color) VALUES (%s, %s)", (rarity["display"], rarity["color"]))
|
||||
|
||||
conn.commit()
|
||||
|
||||
cur.close()
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user