From 73e88349b6b5665c713a5e0c3eb11a5a348c964a Mon Sep 17 00:00:00 2001 From: LDericher <40151420+ldericher@users.noreply.github.com> Date: Tue, 3 Aug 2021 23:41:25 +0200 Subject: [PATCH] opus defined as set of cards --- Pipfile | 1 + Pipfile.lock | 10 +++++++++- fftcg/cards.py | 20 ++++++++++++++++++++ fftcg/opus.py | 24 +++++++++++++----------- main.py | 17 +++-------------- 5 files changed, 46 insertions(+), 26 deletions(-) create mode 100644 fftcg/cards.py diff --git a/Pipfile b/Pipfile index b9ad28e..e5695c4 100644 --- a/Pipfile +++ b/Pipfile @@ -8,6 +8,7 @@ verify_ssl = true [packages] requests = "*" pillow = "*" +roman = "*" [requires] python_version = "3.6" diff --git a/Pipfile.lock b/Pipfile.lock index 84f04f4..4dfa66c 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "f0fedb7b3061de81b354fc95cf267f1b59bce83abd94a44f259ebf7f1e500930" + "sha256": "b4a419cd1c9cb31843b62441f0f8b04d2a88a9b3e4c86e01eb077f9c7f6d6e83" }, "pipfile-spec": 6, "requires": { @@ -92,6 +92,14 @@ "index": "pypi", "version": "==2.26.0" }, + "roman": { + "hashes": [ + "sha256:2c46ac8db827d34e4fa9ccc0577e7f0b0d84f16ffe112351bd4f1ec2eb12d73f", + "sha256:c2a1f14ab47373aecc141edbcdd66595949c9d0ed932fe76bd547df1b55f7278" + ], + "index": "pypi", + "version": "==3.3" + }, "urllib3": { "hashes": [ "sha256:39fb8672126159acb139a7718dd10806104dec1e2f0f6c88aab05d17df10c8d4", diff --git a/fftcg/cards.py b/fftcg/cards.py new file mode 100644 index 0000000..f027fc1 --- /dev/null +++ b/fftcg/cards.py @@ -0,0 +1,20 @@ +import requests + +from .card import Card + +APIURL = "https://fftcg.square-enix-games.com/de/get-cards" + + +class Cards: + def __init__(self, params): + # supported params: + # [str] text (required) + # [array] type, element, cost, rarity, power, category_1, set + # [str] language, code, multicard="○"|"", ex_burst="○"|"", special="《S》"|"" + # [int] exactmatch=0|1 + + req = requests.post(APIURL, json=params) + self.__content = [Card(card_data) for card_data in req.json()["cards"]] + + def __str__(self): + return "\n".join(str(card) for card in self.__content) diff --git a/fftcg/opus.py b/fftcg/opus.py index 80eef04..39f0af0 100644 --- a/fftcg/opus.py +++ b/fftcg/opus.py @@ -1,15 +1,17 @@ -import requests +from roman import toRoman -from .card import Card - -APIURL = "https://fftcg.square-enix-games.com/de/get-cards" +from .cards import Cards -class Opus: - def __init__(self, params): - # self.__cards = [Card(card_data) for card_data in data] - req = requests.post(APIURL, json=params) - self.__cards = [Card(card_data) for card_data in req.json()["cards"]] +class Opus(Cards): + def __init__(self, number): + if isinstance(number, int): + number = f"Opus {toRoman(number)}" - def __str__(self): - return "\n".join(str(card) for card in self.__cards) + params = { + "text": "", + "element": ["fire"], + "set": [number], + } + + Cards.__init__(self, params) diff --git a/main.py b/main.py index 5b0ac78..fa6da43 100755 --- a/main.py +++ b/main.py @@ -3,21 +3,10 @@ from fftcg.opus import Opus -def print_hi(name): - # supported params: - # [str] language, text, - # [array] type, element, cost, rarity, power, category_1, set - # [str] multicard="○"|"", ex_burst="○"|"", code, special="《S》"|"" - # [int] exactmatch=0|1 - params = { - "text": "", - "element": ["fire"], - "set": ["Opus XIV"], - } - - opus = Opus(params) +def main(): + opus = Opus(14) print(opus) if __name__ == '__main__': - print_hi('PyCharm') + main()