diff --git a/README.md b/README.md index 7c6c703..3cb7528 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,15 @@ pipenv run python convert.py examples/decklist_text.txt examples/decklist.txt pipenv run python print.py examples/decklist.txt decklist.pdf ``` +Examples: + +- Create separate outputs for front and back faces + +```bash +pipenv run python print.py examples/decklist.txt decklist_fronts.pdf --face front +pipenv run python print.py examples/decklist.txt decklist_backs.pdf --face back +``` + ## Updating ```bash @@ -111,6 +120,8 @@ optional arguments: --background COLOR background color, either by name or by hex code (e.g. black or "#ff0000", default: None) --cropmarks, --no-cropmarks add crop marks (default: True) + --faces {all,front,back} + which faces to print (default: all) ``` ### convert diff --git a/mtgproxies/scans.py b/mtgproxies/scans.py index bbaa9ac..2597a18 100644 --- a/mtgproxies/scans.py +++ b/mtgproxies/scans.py @@ -1,16 +1,19 @@ from __future__ import annotations +from typing import Literal + from tqdm import tqdm import scryfall from mtgproxies.decklists.decklist import Decklist -def fetch_scans_scryfall(decklist: Decklist) -> list[str]: +def fetch_scans_scryfall(decklist: Decklist, faces: Literal["all", "front", "back"] = "all") -> list[str]: """Search Scryfall for scans of a decklist. Args: - decklist: List of (count, name, set_id, collectors_number)-tuples + decklist: The decklist to fetch scans for + faces: Which faces to fetch ("all", "front", "back") Returns: List: List of image files @@ -18,6 +21,7 @@ def fetch_scans_scryfall(decklist: Decklist) -> list[str]: return [ scan for card in tqdm(decklist.cards, desc="Fetching artwork") - for image_uri in card.image_uris + for i, image_uri in enumerate(card.image_uris) for scan in [scryfall.get_image(image_uri["png"], silent=True)] * card.count + if faces == "all" or (faces == "front" and i == 0) or (faces == "back" and i > 0) ] diff --git a/print.py b/print.py index cdabebe..340a9c7 100644 --- a/print.py +++ b/print.py @@ -54,13 +54,19 @@ def papersize(string: str) -> np.ndarray: metavar="COLOR", ) parser.add_argument("--cropmarks", action=argparse.BooleanOptionalAction, default=True, help="add crop marks") + parser.add_argument( + "--faces", + help="which faces to print (default: %(default)s)", + choices=["all", "front", "back"], + default="all", + ) args = parser.parse_args() # Parse decklist decklist = parse_decklist_spec(args.decklist) # Fetch scans - images = fetch_scans_scryfall(decklist) + images = fetch_scans_scryfall(decklist, faces=args.faces) # Plot cards if args.outfile.endswith(".pdf"): diff --git a/tests/scans_test.py b/tests/scans_test.py new file mode 100644 index 0000000..e35e0d6 --- /dev/null +++ b/tests/scans_test.py @@ -0,0 +1,30 @@ +from pathlib import Path + +import pytest + +from mtgproxies.decklists import Decklist + + +@pytest.fixture(scope="module") +def example_decklist() -> Decklist: + from mtgproxies.decklists import parse_decklist + + decklist, _, _ = parse_decklist(Path(__file__).parent.parent / "examples/decklist.txt") + + return decklist + + +@pytest.mark.parametrize( + "faces,expected_images", + [ + ("all", 7), + ("front", 6), + ("back", 1), + ], +) +def test_fetch_scans_scryfall(example_decklist: Decklist, faces: str, expected_images: int): + from mtgproxies import fetch_scans_scryfall + + images = fetch_scans_scryfall(example_decklist, faces=faces) + + assert len(images) == expected_images