add icon token subdir, Docker, SPEC/AGENTS, initial commit
This commit is contained in:
commit
73eeab7f63
17 files changed
+622
No files matched your search
@@ -0,0 +1,71 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from app.models import (
|
||||
SessionLocal,
|
||||
Token,
|
||||
Version,
|
||||
Base,
|
||||
engine,
|
||||
)
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
SEED_TOKEN = BASE_DIR / "tokenList.json"
|
||||
SEED_VERSION = BASE_DIR / "versionAndroid.json"
|
||||
|
||||
|
||||
def init_db():
|
||||
Base.metadata.create_all(engine)
|
||||
seed()
|
||||
|
||||
|
||||
def seed():
|
||||
session = SessionLocal()
|
||||
try:
|
||||
if session.query(Token).count() == 0 and SEED_TOKEN.exists():
|
||||
data = json.loads(SEED_TOKEN.read_text(encoding="utf-8"))
|
||||
for t in data["tokenList"]:
|
||||
session.add(
|
||||
Token(
|
||||
idfToken=int(t["idfToken"]),
|
||||
position=int(t["position"]),
|
||||
typeBlockchain=t["typeBlockchain"],
|
||||
name=t["name"],
|
||||
symbol=t["symbol"],
|
||||
contractAddr=t["contractAddr"],
|
||||
decimals=int(t["decimals"]),
|
||||
iconUrl=t.get("iconUrl") or "",
|
||||
filename=t.get("filename") or "",
|
||||
is_live=t.get("is_live") in (1, "1", "true", True),
|
||||
)
|
||||
)
|
||||
if session.query(Version).count() == 0 and SEED_VERSION.exists():
|
||||
v = json.loads(SEED_VERSION.read_text(encoding="utf-8"))
|
||||
session.add(
|
||||
Version(
|
||||
id=1,
|
||||
idVersion=int(v["idVersion"]),
|
||||
appName=v["appName"],
|
||||
acceptableVersion=int(v["acceptableVersion"]),
|
||||
latestVersion=int(v["latestVersion"]),
|
||||
)
|
||||
)
|
||||
session.commit()
|
||||
finally:
|
||||
session.close()
|
||||
|
||||
|
||||
def list_tokens():
|
||||
session = SessionLocal()
|
||||
try:
|
||||
return session.query(Token).order_by(Token.position.asc()).all()
|
||||
finally:
|
||||
session.close()
|
||||
|
||||
|
||||
def get_version():
|
||||
session = SessionLocal()
|
||||
try:
|
||||
return session.query(Version).filter(Version.id == 1).first()
|
||||
finally:
|
||||
session.close()
|
||||
Reference in new issue
Block a user