-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added option to only print front or back faces
Closes #18
- Loading branch information
Showing
4 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |