switching to sqlmodel...
This commit is contained in:
109
import_sde.py
Normal file
109
import_sde.py
Normal file
@@ -0,0 +1,109 @@
|
||||
import yaml
|
||||
from eveal.database import engine
|
||||
from sqlmodel import Session, SQLModel
|
||||
from eveal import models_sde
|
||||
|
||||
import os
|
||||
os.remove("eveal.db")
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
|
||||
print("Importing SDE data...")
|
||||
print("Importing icons...")
|
||||
with open("static_eve/sde/fsd/iconIDs.yaml", "r") as f:
|
||||
icons = yaml.safe_load(f)
|
||||
|
||||
with Session(engine) as db:
|
||||
for id, icon in icons.items():
|
||||
db.add(models_sde.Icon(id=id, **icon))
|
||||
db.commit()
|
||||
|
||||
print("Importing categories...")
|
||||
with open("static_eve/sde/fsd/categoryIDs.yaml", "r") as f:
|
||||
categories = yaml.safe_load(f)
|
||||
|
||||
with Session(engine) as db:
|
||||
for id, category in categories.items():
|
||||
db.add(models_sde.Category(id=id,
|
||||
icon_id=category['iconID'] if 'iconID' in category else None,
|
||||
name=category['name']['en'],
|
||||
published=category['published']))
|
||||
db.commit()
|
||||
|
||||
|
||||
print("Importing groups...")
|
||||
with open("static_eve/sde/fsd/groupIDs.yaml", "r") as f:
|
||||
groups = yaml.safe_load(f)
|
||||
|
||||
with Session(engine) as db:
|
||||
for id, group in groups.items():
|
||||
db.add(models_sde.Group(id=id,
|
||||
anchorable=group['anchorable'],
|
||||
anchored=group['anchored'],
|
||||
category_id=group['categoryID'],
|
||||
fittableNonSingletion=group['fittableNonSingleton'],
|
||||
icon_id=group['iconID'] if 'iconID' in group else None,
|
||||
name=group['name']['en'],
|
||||
published=group['published'],
|
||||
useBasePrice=group['useBasePrice']
|
||||
))
|
||||
db.commit()
|
||||
|
||||
|
||||
print("Importing marketgroups...")
|
||||
with open("static_eve/sde/fsd/marketGroups.yaml", "r") as f:
|
||||
marketgroups = yaml.safe_load(f)
|
||||
|
||||
|
||||
with Session(engine) as db:
|
||||
for id, marketgroup in marketgroups.items():
|
||||
db.add(models_sde.MarketGroup(id=id,
|
||||
description=marketgroup['descriptionID']['en'] if 'descriptionID' in marketgroup else None,
|
||||
hasTypes=marketgroup['hasTypes'],
|
||||
icon_id=marketgroup['iconID'] if 'iconID' in marketgroup else None,
|
||||
name=marketgroup['nameID']['en'],
|
||||
parent_marketgroup_id=marketgroup['parentGroupID'] if 'parentGroupID' in marketgroup else None,
|
||||
))
|
||||
db.commit()
|
||||
|
||||
|
||||
print("Importing types...")
|
||||
with open("static_eve/sde/fsd/typeIDs.yaml", "r") as f:
|
||||
types = yaml.safe_load(f)
|
||||
|
||||
with Session(engine) as db:
|
||||
for id, type in types.items():
|
||||
try:
|
||||
db.add(models_sde.Type(id=id,
|
||||
group_id=type['groupID'],
|
||||
marketgroup_id=type['marketGroupID'] if 'marketGroupID' in type else None,
|
||||
name=type['name']['en'],
|
||||
published=type['published'],
|
||||
basePrice=type['basePrice'] if 'basePrice' in type else None,
|
||||
description=type['description']['en'] if 'description' in type else None,
|
||||
icon_id=type['iconID'] if 'iconID' in type else None,
|
||||
portionSize=type['portionSize'],
|
||||
volume=type['volume'] if 'volume' in type else None,
|
||||
))
|
||||
except KeyError:
|
||||
print(type)
|
||||
raise
|
||||
db.commit()
|
||||
|
||||
|
||||
print("Importing materials...")
|
||||
with open("static_eve/sde/fsd/typeMaterials.yaml", "r") as f:
|
||||
materials = yaml.safe_load(f)
|
||||
|
||||
with Session(engine) as db:
|
||||
for id, material in materials.items():
|
||||
for mat in material:
|
||||
db.add(models_sde.TypeMaterial(type_id=id,
|
||||
material_id=mat['materialTypeID'],
|
||||
quantity=mat['quantity']
|
||||
))
|
||||
db.commit()
|
||||
|
||||
|
||||
|
||||
print("DONE!")
|
||||
Reference in New Issue
Block a user