mirror of
https://github.com/ldericher/fftcgtool
synced 2025-01-24 02:23:01 +00:00
pages.yml
This commit is contained in:
parent
99adde52bd
commit
18e1676576
5 changed files with 100 additions and 20 deletions
1
Pipfile
1
Pipfile
|
@ -9,6 +9,7 @@ verify_ssl = true
|
|||
requests = "*"
|
||||
pillow = "*"
|
||||
roman = "*"
|
||||
pyyaml = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.9"
|
||||
|
|
37
Pipfile.lock
generated
37
Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "a2e1b3f733a9b7697e8f974449a04cf81e78f6959a67945afa0e78446d491690"
|
||||
"sha256": "1618a2855eedd09511a3afe86c6d18bff3251e54d303e1d1475774b0c7960dfd"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
|
@ -84,6 +84,41 @@
|
|||
"index": "pypi",
|
||||
"version": "==8.3.1"
|
||||
},
|
||||
"pyyaml": {
|
||||
"hashes": [
|
||||
"sha256:08682f6b72c722394747bddaf0aa62277e02557c0fd1c42cb853016a38f8dedf",
|
||||
"sha256:0f5f5786c0e09baddcd8b4b45f20a7b5d61a7e7e99846e3c799b05c7c53fa696",
|
||||
"sha256:129def1b7c1bf22faffd67b8f3724645203b79d8f4cc81f674654d9902cb4393",
|
||||
"sha256:294db365efa064d00b8d1ef65d8ea2c3426ac366c0c4368d930bf1c5fb497f77",
|
||||
"sha256:3b2b1824fe7112845700f815ff6a489360226a5609b96ec2190a45e62a9fc922",
|
||||
"sha256:3bd0e463264cf257d1ffd2e40223b197271046d09dadf73a0fe82b9c1fc385a5",
|
||||
"sha256:4465124ef1b18d9ace298060f4eccc64b0850899ac4ac53294547536533800c8",
|
||||
"sha256:49d4cdd9065b9b6e206d0595fee27a96b5dd22618e7520c33204a4a3239d5b10",
|
||||
"sha256:4e0583d24c881e14342eaf4ec5fbc97f934b999a6828693a99157fde912540cc",
|
||||
"sha256:5accb17103e43963b80e6f837831f38d314a0495500067cb25afab2e8d7a4018",
|
||||
"sha256:607774cbba28732bfa802b54baa7484215f530991055bb562efbed5b2f20a45e",
|
||||
"sha256:6c78645d400265a062508ae399b60b8c167bf003db364ecb26dcab2bda048253",
|
||||
"sha256:72a01f726a9c7851ca9bfad6fd09ca4e090a023c00945ea05ba1638c09dc3347",
|
||||
"sha256:74c1485f7707cf707a7aef42ef6322b8f97921bd89be2ab6317fd782c2d53183",
|
||||
"sha256:895f61ef02e8fed38159bb70f7e100e00f471eae2bc838cd0f4ebb21e28f8541",
|
||||
"sha256:8c1be557ee92a20f184922c7b6424e8ab6691788e6d86137c5d93c1a6ec1b8fb",
|
||||
"sha256:bb4191dfc9306777bc594117aee052446b3fa88737cd13b7188d0e7aa8162185",
|
||||
"sha256:bfb51918d4ff3d77c1c856a9699f8492c612cde32fd3bcd344af9be34999bfdc",
|
||||
"sha256:c20cfa2d49991c8b4147af39859b167664f2ad4561704ee74c1de03318e898db",
|
||||
"sha256:cb333c16912324fd5f769fff6bc5de372e9e7a202247b48870bc251ed40239aa",
|
||||
"sha256:d2d9808ea7b4af864f35ea216be506ecec180628aced0704e34aca0b040ffe46",
|
||||
"sha256:d483ad4e639292c90170eb6f7783ad19490e7a8defb3e46f97dfe4bacae89122",
|
||||
"sha256:dd5de0646207f053eb0d6c74ae45ba98c3395a571a2891858e87df7c9b9bd51b",
|
||||
"sha256:e1d4970ea66be07ae37a3c2e48b5ec63f7ba6804bdddfdbd3cfd954d25a82e63",
|
||||
"sha256:e4fac90784481d221a8e4b1162afa7c47ed953be40d31ab4629ae917510051df",
|
||||
"sha256:fa5ae20527d8e831e8230cbffd9f8fe952815b2b7dae6ffec25318803a7528fc",
|
||||
"sha256:fd7f6999a8070df521b6384004ef42833b9bd62cfee11a09bda1079b4b704247",
|
||||
"sha256:fdc842473cd33f45ff6bce46aea678a54e3d21f1b61a7750ce3c498eedfe25d6",
|
||||
"sha256:fe69978f3f768926cfa37b867e3843918e012cf83f680806599ddce33c2c68b0"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==5.4.1"
|
||||
},
|
||||
"requests": {
|
||||
"hashes": [
|
||||
"sha256:6c1246513ecd5ecd4528a0906f910e8f0f9c6b8ec72030dc9fd154dc1a6efd24",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
|
||||
import yaml
|
||||
from PIL import Image
|
||||
|
||||
from .cards import Cards
|
||||
|
@ -54,5 +55,24 @@ class Book:
|
|||
return self.__pages[index]["image"]
|
||||
|
||||
def save(self, filename: str) -> None:
|
||||
pages: dict[str, dict[str, any]]
|
||||
|
||||
# load pages.yml file
|
||||
try:
|
||||
with open("pages.yml", "r") as file:
|
||||
pages = yaml.load(file)
|
||||
except FileNotFoundError:
|
||||
pages = {}
|
||||
|
||||
# save book
|
||||
for i, page in enumerate(self.__pages):
|
||||
page["image"].save(f"{filename}_{i}.jpg")
|
||||
fn = f"{filename}_{i}.jpg"
|
||||
# save page image
|
||||
page["image"].save(fn)
|
||||
# add contents of image
|
||||
pages[fn] = {}
|
||||
pages[fn]["cards"] = page["cards"] # [card.code for card in page["cards"]]
|
||||
|
||||
# update pages.yml file
|
||||
with open("pages.yml", "w") as file:
|
||||
yaml.dump(pages, file)
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
import json
|
||||
import re
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
class Card(yaml.YAMLObject):
|
||||
yaml_tag = u'!Card'
|
||||
|
||||
class Card:
|
||||
__ELEMENTS_MAP = {
|
||||
"火": "Fire",
|
||||
"氷": "Ice",
|
||||
|
@ -13,45 +18,64 @@ class Card:
|
|||
"闇": "Darkness"
|
||||
}
|
||||
|
||||
def __init__(self, data: dict[str, any], language: str = "EN"):
|
||||
def __init__(self, opus, serial, rarity, elements, name, text):
|
||||
self.__opus = opus
|
||||
self.__serial = serial
|
||||
self.__rarity = rarity
|
||||
self.__elements = elements
|
||||
self.__name = name
|
||||
self.__text = text
|
||||
|
||||
@classmethod
|
||||
def from_data(cls, data: dict[str, any], language: str):
|
||||
if not data:
|
||||
self.__opus = "0"
|
||||
self.__serial = "000"
|
||||
self.__rarity = "X"
|
||||
self.__elements = []
|
||||
self.__name = None
|
||||
self.__text = None
|
||||
return cls(
|
||||
opus="0",
|
||||
serial="000",
|
||||
rarity="X",
|
||||
elements=[],
|
||||
name=None,
|
||||
text=None,
|
||||
)
|
||||
|
||||
else:
|
||||
if str(data["Code"])[0].isnumeric():
|
||||
# card code starts with a number
|
||||
self.__opus, self.__serial, self.__rarity = \
|
||||
opus, serial, rarity = \
|
||||
re.match(r"([0-9]+)-([0-9]+)([CRHLS])", data["Code"]).groups()
|
||||
|
||||
elif str(data["Code"]).startswith("PR"):
|
||||
# card code starts with "PR"
|
||||
self.__opus, self.__serial = \
|
||||
opus, serial = \
|
||||
re.match(r"(PR)-([0-9]+)", data["Code"]).groups()
|
||||
self.__rarity = ""
|
||||
rarity = ""
|
||||
|
||||
elif str(data["Code"]).startswith("B"):
|
||||
# card code starts with "B"
|
||||
self.__opus, self.__serial = \
|
||||
opus, serial = \
|
||||
re.match(r"(B)-([0-9]+)", data["Code"]).groups()
|
||||
self.__rarity = ""
|
||||
rarity = ""
|
||||
|
||||
else:
|
||||
# card code not recognized
|
||||
self.__opus, self.__serial, self.__rarity = \
|
||||
opus, serial, rarity = \
|
||||
"?", "???", "?"
|
||||
|
||||
self.__elements = [Card.__ELEMENTS_MAP[element] for element in data["Element"].split("/")]
|
||||
self.__name = data[f"Name_{language}"]
|
||||
self.__text = data[f"Text_{language}"]
|
||||
return cls(
|
||||
opus=opus,
|
||||
serial=serial,
|
||||
rarity=rarity,
|
||||
elements=[Card.__ELEMENTS_MAP[element] for element in data["Element"].split("/")],
|
||||
name=data[f"Name_{language}"],
|
||||
text=data[f"Text_{language}"],
|
||||
)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"'{self.__name}' ({'/'.join(self.__elements)}, {self.code})"
|
||||
|
||||
def to_json(self) -> str:
|
||||
return json.dumps(self, default=lambda o: o.__dict__)
|
||||
|
||||
# 6-048C
|
||||
@property
|
||||
def code(self) -> str:
|
||||
|
|
|
@ -18,7 +18,7 @@ class Cards(list[Card]):
|
|||
params["text"] = ""
|
||||
|
||||
req = requests.post(Cards.__API_URL, json=params)
|
||||
super().__init__([Card(card_data) for card_data in req.json()["cards"]])
|
||||
super().__init__([Card.from_data(card_data, "EN") for card_data in req.json()["cards"]])
|
||||
|
||||
def __str__(self) -> str:
|
||||
return "\n".join(str(card) for card in self)
|
||||
|
|
Loading…
Reference in a new issue