Skip to content

Commit

Permalink
Added option to only print front or back faces
Browse files Browse the repository at this point in the history
Closes #18
  • Loading branch information
DiddiZ committed Feb 22, 2024
1 parent c744cf3 commit 98f90b0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions mtgproxies/scans.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
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
"""
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)
]
8 changes: 7 additions & 1 deletion print.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
30 changes: 30 additions & 0 deletions tests/scans_test.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 98f90b0

Please sign in to comment.