remove fastapi
This commit is contained in:
@@ -1,17 +0,0 @@
|
|||||||
import os
|
|
||||||
from sqlmodel import create_engine, Session
|
|
||||||
|
|
||||||
|
|
||||||
if os.getenv("POSTGRES_HOST"):
|
|
||||||
engine = create_engine(f"postgresql://{os.getenv('POSTGRES_USER')}:{os.getenv('POSTGRES_PASSWORD')}@{os.getenv('POSTGRES_HOST')}/{os.getenv('POSTGRES_DB')}",
|
|
||||||
echo=False, future=True)
|
|
||||||
else:
|
|
||||||
sqlite_file_name = os.getenv("SQLITE_DB_PATH", "eveal.db")
|
|
||||||
engine = create_engine(f"sqlite:///{sqlite_file_name}", echo=True, future=True, connect_args={"check_same_thread": False})
|
|
||||||
|
|
||||||
def get_session():
|
|
||||||
db = Session(engine)
|
|
||||||
try:
|
|
||||||
yield db
|
|
||||||
finally:
|
|
||||||
db.close()
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
from fastapi import FastAPI, Depends
|
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
|
||||||
from typing import List, Dict
|
|
||||||
from sqlmodel import SQLModel, Session
|
|
||||||
|
|
||||||
from eveal.schemas import Evepraisal, PriceReprocess
|
|
||||||
from eveal.database import engine, get_session
|
|
||||||
from eveal import models_sde
|
|
||||||
from api import esi
|
|
||||||
|
|
||||||
SQLModel.metadata.create_all(engine) # use alembic?
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"])
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
|
||||||
async def root():
|
|
||||||
return {"message": "Hello World"}
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/reprocess/")
|
|
||||||
async def reprocess(ep_items: Evepraisal, ep_mat: Evepraisal, efficiency: float = .55, db: Session = Depends(get_session)) -> List[PriceReprocess]:
|
|
||||||
matprices = {item.typeID: {'sell': item.prices.sell.min, 'buy': item.prices.buy.max} for item in ep_mat.items}
|
|
||||||
|
|
||||||
item_reprocess: List[PriceReprocess] = []
|
|
||||||
for rawitem in ep_items.items:
|
|
||||||
item = db.get(models_sde.SDEType, rawitem.typeID)
|
|
||||||
buy_reprocess = sell_reprocess = 0.0
|
|
||||||
for mat in item.materials.all():
|
|
||||||
buy_reprocess += matprices[mat.material_type_id]['buy'] * mat.quantity/mat.type.portionSize * efficiency
|
|
||||||
sell_reprocess += matprices[mat.material_type_id]['sell'] * mat.quantity/mat.type.portionSize * efficiency
|
|
||||||
item_reprocess.append(PriceReprocess(typeID=rawitem.typeID,
|
|
||||||
buy=rawitem.prices.buy.max,
|
|
||||||
sell=rawitem.prices.sell.min,
|
|
||||||
buy_reprocess=buy_reprocess,
|
|
||||||
sell_reprocess=sell_reprocess,
|
|
||||||
name=rawitem.name
|
|
||||||
))
|
|
||||||
return item_reprocess
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/sde/types/{sde_type}/")
|
|
||||||
async def sde_types(sde_type: int | str, db: Session = Depends(get_session)) -> models_sde.SDEType:
|
|
||||||
try:
|
|
||||||
item = db.get(models_sde.SDEType, int(sde_type))
|
|
||||||
except ValueError:
|
|
||||||
item = db.query(models_sde.SDEType).filter(models_sde.SDEType.name == sde_type).one()
|
|
||||||
return item
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/sde/types/search")
|
|
||||||
async def sde_types_search(query: List[Dict[str, int | str | None | List]], db: Session = Depends(get_session)) -> List[models_sde.SDEType]:
|
|
||||||
items = []
|
|
||||||
for q in query:
|
|
||||||
qitems = db.query(models_sde.SDEType)
|
|
||||||
for k in q.keys():
|
|
||||||
value = q[k]
|
|
||||||
|
|
||||||
tokens = k.split("__")
|
|
||||||
key, mods = tokens[0], tokens[1:]
|
|
||||||
|
|
||||||
if "i" in mods:
|
|
||||||
condition = getattr(models_sde.SDEType, key).ilike(f"%{value}%") # change to icontains when sqlmodel start using sqlalchemy > 2.0
|
|
||||||
elif "in" in mods:
|
|
||||||
condition = getattr(models_sde.SDEType, key).in_(value)
|
|
||||||
else:
|
|
||||||
condition = getattr(models_sde.SDEType, key) == value
|
|
||||||
|
|
||||||
if "not" in mods:
|
|
||||||
condition = ~condition
|
|
||||||
|
|
||||||
qitems = qitems.filter(condition)
|
|
||||||
items.extend(qitems.all())
|
|
||||||
return items
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/esi/types/{sde_type}/market/{region_id}/")
|
|
||||||
async def sde_types_market(sde_type: int | str, region_id: int | str, db: Session = Depends(get_session)):
|
|
||||||
"""Get market orders for a type in a region. example: /esi/types/22291/market/10000002/"""
|
|
||||||
"""TODO: use ESIMarketOrder"""
|
|
||||||
return list(
|
|
||||||
esi.esi_client.Market.get_markets_region_id_orders(order_type="all", type_id=sde_type, region_id=region_id))
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/_tools/get_all_mat")
|
|
||||||
async def _get_all_mat(db: Session = Depends(get_session)):
|
|
||||||
materials = db.query(models_sde.SDETypeMaterial).filter(models_sde.SDETypeMaterial.type.has(models_sde.SDEType.published == True)).all()
|
|
||||||
allmat = set()
|
|
||||||
for mat in materials:
|
|
||||||
allmat.add(mat.material_type.name)
|
|
||||||
return allmat
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
import uvicorn
|
|
||||||
uvicorn.run("eveal.main:app", host="0.0.0.0", port=8000, reload=True)
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
from datetime import datetime
|
|
||||||
from typing import Optional, List
|
|
||||||
from sqlmodel import SQLModel, Field, Relationship
|
|
||||||
|
|
||||||
|
|
||||||
class ESIMarketOrder(SQLModel, table=True):
|
|
||||||
id: Optional[int] = Field(default=None, primary_key=True)
|
|
||||||
timestamp: datetime = Field(default_factory=datetime.utcnow, nullable=False)
|
|
||||||
|
|
||||||
region_id: int
|
|
||||||
type_id: int # TODO: link to SDE
|
|
||||||
location_id: int # TODO: link to SDE
|
|
||||||
volume_total: int
|
|
||||||
volume_remain: int
|
|
||||||
min_volume: int
|
|
||||||
order_id: int # TODO: use this as PK ? (will lose volume_remain history)
|
|
||||||
price: float
|
|
||||||
is_buy_order: bool
|
|
||||||
duration: int
|
|
||||||
issued: datetime
|
|
||||||
range: str # TODO: enum?
|
|
||||||
system_id: int # TODO: link to SDE
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
from typing import Optional, List
|
|
||||||
from sqlmodel import SQLModel, Field, Relationship
|
|
||||||
from functools import partial
|
|
||||||
|
|
||||||
DynamicRelationship = partial(Relationship, sa_relationship_kwargs={"lazy": "dynamic"}) # change default lazy loading to dynamic
|
|
||||||
|
|
||||||
|
|
||||||
class SDEIcon(SQLModel, table=True):
|
|
||||||
id: Optional[int] = Field(default=None, primary_key=True)
|
|
||||||
|
|
||||||
description: Optional[str] = None
|
|
||||||
iconFile: str
|
|
||||||
|
|
||||||
categories: List['SDECategory'] = DynamicRelationship(back_populates="icon")
|
|
||||||
groups: List['SDEGroup'] = DynamicRelationship(back_populates="icon")
|
|
||||||
marketgroups: List['SDEMarketGroup'] = DynamicRelationship(back_populates="icon")
|
|
||||||
types: List['SDEType'] = DynamicRelationship(back_populates="icon")
|
|
||||||
metagroups: List['SDEMetaGroup'] = DynamicRelationship(back_populates="icon")
|
|
||||||
|
|
||||||
|
|
||||||
class SDECategory(SQLModel, table=True):
|
|
||||||
id: Optional[int] = Field(default=None, primary_key=True)
|
|
||||||
|
|
||||||
icon_id: Optional[int] = Field(default=None, foreign_key="sdeicon.id")
|
|
||||||
icon: Optional[SDEIcon] = Relationship(back_populates="categories")
|
|
||||||
|
|
||||||
name: str
|
|
||||||
published: bool
|
|
||||||
|
|
||||||
groups: List['SDEGroup'] = DynamicRelationship(back_populates="category")
|
|
||||||
|
|
||||||
|
|
||||||
class SDEGroup(SQLModel, table=True):
|
|
||||||
id: Optional[int] = Field(default=None, primary_key=True)
|
|
||||||
|
|
||||||
anchorable: bool
|
|
||||||
anchored: bool
|
|
||||||
|
|
||||||
category_id: Optional[int] = Field(default=None, foreign_key="sdecategory.id")
|
|
||||||
category: Optional[SDECategory] = Relationship(back_populates="groups")
|
|
||||||
|
|
||||||
fittableNonSingletion: bool
|
|
||||||
|
|
||||||
icon_id: Optional[int] = Field(default=None, foreign_key="sdeicon.id")
|
|
||||||
icon: Optional[SDEIcon] = Relationship(back_populates="groups")
|
|
||||||
|
|
||||||
name: str
|
|
||||||
published: bool
|
|
||||||
useBasePrice: bool
|
|
||||||
|
|
||||||
types: List['SDEType'] = DynamicRelationship(back_populates="group")
|
|
||||||
|
|
||||||
|
|
||||||
class SDEMarketGroup(SQLModel, table=True):
|
|
||||||
id: Optional[int] = Field(default=None, primary_key=True)
|
|
||||||
|
|
||||||
description: Optional[str] = None
|
|
||||||
hasTypes: bool
|
|
||||||
|
|
||||||
icon_id: Optional[int] = Field(default=None, foreign_key="sdeicon.id")
|
|
||||||
icon: Optional[SDEIcon] = Relationship(back_populates="marketgroups")
|
|
||||||
|
|
||||||
name: str
|
|
||||||
|
|
||||||
parent_marketgroup_id: Optional[int] = Field(default=None, foreign_key="sdemarketgroup.id")
|
|
||||||
parent_marketgroup: Optional['SDEMarketGroup'] = Relationship(back_populates="children_marketgroups",
|
|
||||||
sa_relationship_kwargs={"remote_side": 'SDEMarketGroup.id'}) # workaround for self reference: https://github.com/tiangolo/sqlmodel/issues/127#issuecomment-1224135123
|
|
||||||
children_marketgroups: List['SDEMarketGroup'] = DynamicRelationship(back_populates="parent_marketgroup")
|
|
||||||
|
|
||||||
types: List['SDEType'] = DynamicRelationship(back_populates="marketgroup")
|
|
||||||
|
|
||||||
|
|
||||||
class SDEMetaGroup(SQLModel, table=True):
|
|
||||||
id: int = Field(primary_key=True)
|
|
||||||
|
|
||||||
name: str
|
|
||||||
iconSuffix: Optional[str] = None
|
|
||||||
|
|
||||||
icon_id: Optional[int] = Field(default=None, foreign_key="sdeicon.id")
|
|
||||||
icon: Optional[SDEIcon] = Relationship(back_populates="metagroups")
|
|
||||||
|
|
||||||
types: List['SDEType'] = DynamicRelationship(back_populates="metagroup")
|
|
||||||
|
|
||||||
|
|
||||||
class SDEType(SQLModel, table=True):
|
|
||||||
id: int = Field(primary_key=True)
|
|
||||||
|
|
||||||
group_id: Optional[int] = Field(default=None, foreign_key="sdegroup.id")
|
|
||||||
group: Optional[SDEGroup] = Relationship(back_populates="types")
|
|
||||||
|
|
||||||
marketgroup_id: Optional[int] = Field(default=None, foreign_key="sdemarketgroup.id")
|
|
||||||
marketgroup: Optional[SDEMarketGroup] = Relationship(back_populates="types")
|
|
||||||
|
|
||||||
metagroup_id: Optional[int] = Field(default=None, foreign_key="sdemetagroup.id")
|
|
||||||
metagroup: Optional[SDEMetaGroup] = Relationship(back_populates="types")
|
|
||||||
|
|
||||||
name: str
|
|
||||||
published: bool = False
|
|
||||||
description: Optional[str] = None
|
|
||||||
basePrice: Optional[float] = None
|
|
||||||
|
|
||||||
icon_id: Optional[int] = Field(default=None, foreign_key="sdeicon.id")
|
|
||||||
icon: Optional[SDEIcon] = Relationship(back_populates="types")
|
|
||||||
|
|
||||||
volume: Optional[float] = None
|
|
||||||
portionSize: int
|
|
||||||
|
|
||||||
materials: List['SDETypeMaterial'] = DynamicRelationship(back_populates="type",
|
|
||||||
sa_relationship_kwargs={"lazy": "dynamic", "foreign_keys": '[SDETypeMaterial.type_id]'}) # https://github.com/tiangolo/sqlmodel/issues/10#issuecomment-1537445078
|
|
||||||
material_of: List['SDETypeMaterial'] = DynamicRelationship(back_populates="material_type",
|
|
||||||
sa_relationship_kwargs={"lazy": "dynamic", "foreign_keys": '[SDETypeMaterial.material_type_id]'}) # https://github.com/tiangolo/sqlmodel/issues/10#issuecomment-1537445078
|
|
||||||
|
|
||||||
|
|
||||||
class SDETypeMaterial(SQLModel, table=True):
|
|
||||||
id: Optional[int] = Field(default=None, primary_key=True)
|
|
||||||
|
|
||||||
type_id: Optional[int] = Field(default=None, foreign_key="sdetype.id")
|
|
||||||
type: Optional[SDEType] = Relationship(back_populates="materials",
|
|
||||||
sa_relationship_kwargs={"primaryjoin": 'SDETypeMaterial.type_id==SDEType.id',
|
|
||||||
'lazy': 'joined'}) # workaround: https://github.com/tiangolo/sqlmodel/issues/10#issuecomment-1002835506
|
|
||||||
|
|
||||||
material_type_id: Optional[int] = Field(default=None, foreign_key="sdetype.id")
|
|
||||||
material_type: Optional[SDEType] = Relationship(back_populates="material_of",
|
|
||||||
sa_relationship_kwargs={"primaryjoin": 'SDETypeMaterial.material_type_id==SDEType.id',
|
|
||||||
'lazy': 'joined'}) # workaround: https://github.com/tiangolo/sqlmodel/issues/10#issuecomment-1002835506
|
|
||||||
|
|
||||||
quantity: int
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
from pydantic import BaseModel
|
|
||||||
|
|
||||||
|
|
||||||
class Price(BaseModel):
|
|
||||||
avg: float
|
|
||||||
max: float
|
|
||||||
median: float
|
|
||||||
min: float
|
|
||||||
percentile: float
|
|
||||||
stddev: float
|
|
||||||
volume: int
|
|
||||||
order_count: int
|
|
||||||
|
|
||||||
class Prices(BaseModel):
|
|
||||||
all: Price
|
|
||||||
buy: Price
|
|
||||||
sell: Price
|
|
||||||
|
|
||||||
|
|
||||||
class Item(BaseModel):
|
|
||||||
name: str
|
|
||||||
typeID: int
|
|
||||||
typeName: str
|
|
||||||
typeVolume: float
|
|
||||||
quantity: int
|
|
||||||
prices: Prices
|
|
||||||
|
|
||||||
class Total_price(BaseModel):
|
|
||||||
buy: float
|
|
||||||
sell: float
|
|
||||||
volume: float
|
|
||||||
|
|
||||||
class Evepraisal(BaseModel):
|
|
||||||
id: str
|
|
||||||
created: int
|
|
||||||
kind: str
|
|
||||||
market_name: str
|
|
||||||
items: list[Item]
|
|
||||||
totals: Total_price
|
|
||||||
price_percentage: float
|
|
||||||
raw: str
|
|
||||||
|
|
||||||
|
|
||||||
class PriceReprocess(BaseModel):
|
|
||||||
typeID: int
|
|
||||||
buy: float
|
|
||||||
sell: float
|
|
||||||
buy_reprocess: float
|
|
||||||
sell_reprocess: float
|
|
||||||
name: str
|
|
||||||
|
|
||||||
|
|
||||||
166
import_sde.py
166
import_sde.py
@@ -1,166 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
print("Importing SDE data...")
|
|
||||||
print("Importing icons...")
|
|
||||||
with open("static_eve/sde/fsd/iconIDs.yaml", "r", encoding="utf-8") as f:
|
|
||||||
icons = yaml.safe_load(f)
|
|
||||||
new_icons = total_icons = 0
|
|
||||||
with Session(engine) as db:
|
|
||||||
for id, icon in icons.items():
|
|
||||||
db_icon = db.get(models_sde.SDEIcon, id)
|
|
||||||
if not db_icon:
|
|
||||||
db_icon = models_sde.SDEIcon(id=id)
|
|
||||||
db.add(db_icon)
|
|
||||||
new_icons += 1
|
|
||||||
db_icon.iconFile = icon['iconFile']
|
|
||||||
db_icon.description = icon['description'] if 'description' in icon else None
|
|
||||||
total_icons += 1
|
|
||||||
db.commit()
|
|
||||||
print(f"Imported {new_icons} new icons / {total_icons} total icons.")
|
|
||||||
|
|
||||||
|
|
||||||
print("Importing categories...")
|
|
||||||
with open("static_eve/sde/fsd/categoryIDs.yaml", "r", encoding="utf-8") as f:
|
|
||||||
categories = yaml.safe_load(f)
|
|
||||||
new_categories = total_categories = 0
|
|
||||||
with Session(engine) as db:
|
|
||||||
for id, category in categories.items():
|
|
||||||
# if category["published"] == False:
|
|
||||||
# continue
|
|
||||||
db_category = db.get(models_sde.SDECategory, id)
|
|
||||||
if not db_category:
|
|
||||||
db_category = models_sde.SDECategory(id=id)
|
|
||||||
db.add(db_category)
|
|
||||||
new_categories += 1
|
|
||||||
db_category.name = category['name']['en']
|
|
||||||
db_category.published = category['published']
|
|
||||||
db_category.icon_id = category['iconID'] if 'iconID' in category else None
|
|
||||||
total_categories += 1
|
|
||||||
db.commit()
|
|
||||||
print(f"Imported {new_categories} new categories / {total_categories} total categories.")
|
|
||||||
|
|
||||||
|
|
||||||
print("Importing groups...")
|
|
||||||
with open("static_eve/sde/fsd/groupIDs.yaml", "r", encoding="utf-8") as f:
|
|
||||||
groups = yaml.safe_load(f)
|
|
||||||
new_groups = total_groups = 0
|
|
||||||
with Session(engine) as db:
|
|
||||||
for id, group in groups.items():
|
|
||||||
# if group["published"] == False:
|
|
||||||
# continue
|
|
||||||
db_group = db.get(models_sde.SDEGroup, id)
|
|
||||||
if not db_group:
|
|
||||||
db_group = models_sde.SDEGroup(id=id)
|
|
||||||
db.add(db_group)
|
|
||||||
new_groups += 1
|
|
||||||
db_group.anchorable = group['anchorable']
|
|
||||||
db_group.anchored = group['anchored']
|
|
||||||
db_group.category_id = group['categoryID']
|
|
||||||
db_group.fittableNonSingletion = group['fittableNonSingleton']
|
|
||||||
db_group.icon_id = group['iconID'] if 'iconID' in group else None
|
|
||||||
db_group.name = group['name']['en']
|
|
||||||
db_group.published = group['published']
|
|
||||||
db_group.useBasePrice = group['useBasePrice']
|
|
||||||
total_groups += 1
|
|
||||||
db.commit()
|
|
||||||
print(f"Imported {new_groups} new groups / {total_groups} total groups.")
|
|
||||||
|
|
||||||
|
|
||||||
print("Importing marketgroups...")
|
|
||||||
with open("static_eve/sde/fsd/marketGroups.yaml", "r", encoding="utf-8") as f:
|
|
||||||
marketgroups = yaml.safe_load(f)
|
|
||||||
new_marketgroups = total_marketgroups = 0
|
|
||||||
with Session(engine) as db:
|
|
||||||
for id, marketgroup in marketgroups.items():
|
|
||||||
db_marketgroups = db.get(models_sde.SDEMarketGroup, id)
|
|
||||||
if not db_marketgroups:
|
|
||||||
db_marketgroups = models_sde.SDEMarketGroup(id=id)
|
|
||||||
db.add(db_marketgroups)
|
|
||||||
new_marketgroups += 1
|
|
||||||
db_marketgroups.description = marketgroup['descriptionID']['en'] if 'descriptionID' in marketgroup else None
|
|
||||||
db_marketgroups.hasTypes = marketgroup['hasTypes']
|
|
||||||
db_marketgroups.icon_id = marketgroup['iconID'] if 'iconID' in marketgroup else None
|
|
||||||
db_marketgroups.name = marketgroup['nameID']['en']
|
|
||||||
# db_marketgroups.parent_marketgroup_id = marketgroup['parentGroupID'] if 'parentGroupID' in marketgroup else None
|
|
||||||
total_marketgroups += 1
|
|
||||||
db.commit()
|
|
||||||
print(f"Imported {new_marketgroups} marketgroups / {total_marketgroups} total marketgroups.")
|
|
||||||
print("Setting up marketgroup Parents...")
|
|
||||||
total_marketgroup_links = 0
|
|
||||||
with Session(engine) as db:
|
|
||||||
for id, marketgroup in marketgroups.items():
|
|
||||||
db_marketgroups = db.get(models_sde.SDEMarketGroup, id)
|
|
||||||
db_marketgroups.parent_marketgroup_id = marketgroup['parentGroupID'] if 'parentGroupID' in marketgroup else None
|
|
||||||
total_marketgroup_links += 1
|
|
||||||
db.commit()
|
|
||||||
print(f"Updated {total_marketgroup_links} marketgroup Parents")
|
|
||||||
|
|
||||||
|
|
||||||
print("Importing metagroups...")
|
|
||||||
with open("static_eve/sde/fsd/metaGroups.yaml", "r", encoding="utf-8") as f:
|
|
||||||
metagroups = yaml.safe_load(f)
|
|
||||||
new_metagroups = total_metagroups = 0
|
|
||||||
with Session(engine) as db:
|
|
||||||
for id, metagroup in metagroups.items():
|
|
||||||
db_metagroups = db.get(models_sde.SDEMetaGroup, id)
|
|
||||||
if not db_metagroups:
|
|
||||||
db_metagroups = models_sde.SDEMetaGroup(id=id)
|
|
||||||
db.add(db_metagroups)
|
|
||||||
new_metagroups += 1
|
|
||||||
db_metagroups.name = metagroup['nameID']['en']
|
|
||||||
db_metagroups.iconSuffix = metagroup['iconSuffix'] if 'iconSuffix' in metagroup else None
|
|
||||||
db_metagroups.icon_id = metagroup['iconID'] if 'iconID' in metagroup else None
|
|
||||||
total_metagroups += 1
|
|
||||||
db.commit()
|
|
||||||
print(f"Imported {new_metagroups} metagroups / {total_metagroups} total metagroups.")
|
|
||||||
|
|
||||||
|
|
||||||
print("Importing types...")
|
|
||||||
with open("static_eve/sde/fsd/typeIDs.yaml", "r", encoding="utf-8") as f:
|
|
||||||
types = yaml.safe_load(f)
|
|
||||||
new_types = total_types = 0
|
|
||||||
with Session(engine) as db:
|
|
||||||
for id, type in types.items():
|
|
||||||
# if type["published"] == False:
|
|
||||||
# continue
|
|
||||||
db_type = db.get(models_sde.SDEType, id)
|
|
||||||
if not db_type:
|
|
||||||
db_type = models_sde.SDEType(id=id)
|
|
||||||
db.add(db_type)
|
|
||||||
new_types += 1
|
|
||||||
db_type.group_id = type['groupID']
|
|
||||||
db_type.marketgroup_id = type['marketGroupID'] if 'marketGroupID' in type else None
|
|
||||||
db_type.name = type['name']['en']
|
|
||||||
db_type.published = type['published']
|
|
||||||
db_type.basePrice = type['basePrice'] if 'basePrice' in type else None
|
|
||||||
db_type.description = type['description']['en'] if 'description' in type else None
|
|
||||||
db_type.icon_id = type['iconID'] if 'iconID' in type else None
|
|
||||||
db_type.portionSize = type['portionSize']
|
|
||||||
db_type.volume = type['volume'] if 'volume' in type else None
|
|
||||||
db_type.metagroup_id = type['metaGroupID'] if 'metaGroupID' in type else None
|
|
||||||
total_types += 1
|
|
||||||
db.commit()
|
|
||||||
print(f"Imported {new_types} types / {total_types} total types.")
|
|
||||||
|
|
||||||
|
|
||||||
print("Importing materials...")
|
|
||||||
with open("static_eve/sde/fsd/typeMaterials.yaml", "r", encoding="utf-8") as f:
|
|
||||||
materials = yaml.safe_load(f)
|
|
||||||
new_typemat = total_typemat = 0
|
|
||||||
with Session(engine) as db:
|
|
||||||
for id, material in materials.items():
|
|
||||||
for mat in material['materials']:
|
|
||||||
db_typemat = db.query(models_sde.SDETypeMaterial).filter(models_sde.SDETypeMaterial.type_id == id, models_sde.SDETypeMaterial.material_type_id == mat['materialTypeID']).one_or_none()
|
|
||||||
if not db_typemat:
|
|
||||||
db_typemat = models_sde.SDETypeMaterial()
|
|
||||||
db.add(db_typemat)
|
|
||||||
new_typemat += 1
|
|
||||||
db_typemat.type_id = id
|
|
||||||
db_typemat.material_type_id = mat['materialTypeID']
|
|
||||||
db_typemat.quantity = mat['quantity']
|
|
||||||
total_typemat += 1
|
|
||||||
db.commit()
|
|
||||||
print(f"Imported {new_typemat} materials / {total_typemat} total materials.")
|
|
||||||
|
|
||||||
|
|
||||||
print("DONE!")
|
|
||||||
Reference in New Issue
Block a user