🗃️ Store melee data into SQLite
This commit is contained in:
parent
8b847e0f9c
commit
c0fc97a578
7 changed files with 73 additions and 23 deletions
10
data/convert/31-0/db.py
Normal file
10
data/convert/31-0/db.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from pony.orm import *
|
||||
|
||||
db = Database()
|
||||
|
||||
|
||||
class Melee(db.Entity):
|
||||
name = Required(str)
|
||||
description = Optional(str)
|
||||
mechanism = Optional(str)
|
||||
icon = Required(bytes)
|
|
@ -3,36 +3,57 @@
|
|||
|
||||
import json
|
||||
import re
|
||||
import io
|
||||
from db import *
|
||||
from PIL import Image
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
with open("../../extraction/raw-31-0/data.cdb.json") as f:
|
||||
raw = json.load(f)
|
||||
with open("../../clean/31-0/main.zh.mo.json") as f:
|
||||
trans = json.load(f)
|
||||
img = Image.open("../../extraction/raw-31-0/cardIcons.png")
|
||||
|
||||
db.bind(provider="sqlite", filename="../../clean/31-0/data.sqlite3")
|
||||
db.generate_mapping(create_tables=True)
|
||||
|
||||
lines = raw["sheets"][1]["lines"]
|
||||
melee = []
|
||||
|
||||
for i in lines:
|
||||
if i["group"] == 4:
|
||||
melee.append(i)
|
||||
i["name"] = trans[i["name"]]["msgstr"][0]
|
||||
if "ambiantDesc" in i:
|
||||
i["ambiantDesc"] = trans[i["ambiantDesc"].strip()]["msgstr"][0]
|
||||
if "gameplayDesc" in i:
|
||||
i["gameplayDesc"] = trans[i["gameplayDesc"].strip()]["msgstr"][0]
|
||||
if i["props"]:
|
||||
with db_session:
|
||||
for i in lines:
|
||||
if i["group"] == 4:
|
||||
i["name"] = trans[i["name"]]["msgstr"][0]
|
||||
if "ambiantDesc" in i:
|
||||
i["ambiantDesc"] = trans[i["ambiantDesc"].strip()]["msgstr"][0]
|
||||
else:
|
||||
i["ambiantDesc"] = ""
|
||||
if "gameplayDesc" in i:
|
||||
i["gameplayDesc"] = trans[i["gameplayDesc"].strip()]["msgstr"][0]
|
||||
if i["props"]:
|
||||
|
||||
def replace_props(m):
|
||||
result = i["props"][m.group(1)]
|
||||
if isinstance(result, list):
|
||||
result = result[0]
|
||||
if not isinstance(result, str):
|
||||
result = str(result)
|
||||
return result
|
||||
def replace_props(m):
|
||||
result = i["props"][m.group(1)]
|
||||
if isinstance(result, list):
|
||||
result = result[0]
|
||||
if not isinstance(result, str):
|
||||
result = str(result)
|
||||
return result
|
||||
|
||||
i["gameplayDesc"], _ = re.subn(
|
||||
r"::\+?(.*?)::", replace_props, i["gameplayDesc"]
|
||||
)
|
||||
i["gameplayDesc"], _ = re.subn(
|
||||
r"::\+?(.*?)::", replace_props, i["gameplayDesc"]
|
||||
)
|
||||
else:
|
||||
i["gameplayDesc"] = ""
|
||||
x = i["icon"]["x"] * 24
|
||||
y = i["icon"]["y"] * 24
|
||||
box = (x, y, x + 24, y + 24)
|
||||
region = img.crop(box)
|
||||
region_arr = io.BytesIO()
|
||||
region.save(region_arr, format="PNG")
|
||||
|
||||
|
||||
print(json.dumps(melee, ensure_ascii=False))
|
||||
Melee(
|
||||
name=i["name"],
|
||||
description=i["ambiantDesc"],
|
||||
mechanism=i["gameplayDesc"],
|
||||
icon=region_arr.getbuffer().tobytes()
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue