Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/invvd/mtg-cheaper-deck/llms.txt

Use this file to discover all available pages before exploring further.

The card_images module generates a self-contained HTML page that displays an original card next to its cheaper suggested replacements, then opens it in the system’s default browser. No images are downloaded or stored locally — each <img> tag points directly to a Scryfall endpoint that redirects to the actual card scan. The page is written to ./data/compare.html by default and is regenerated on every invocation.

Constants

IMAGE_URL_TMPL = "https://api.scryfall.com/cards/{scryfall_id}?format=image&version=normal"
COMPARE_HTML_PATH = "./data/compare.html"
IMAGE_URL_TMPL is the URL pattern used to fetch card images. Scryfall redirects requests to this endpoint to the actual image hosted on their CDN. The version=normal parameter requests the standard-resolution scan (approximately 488 × 680 pixels), which is the right size for side-by-side display. No API key is required. COMPARE_HTML_PATH is the default path where open_comparison() writes the generated HTML file. The data/ directory is created automatically if it does not exist.

card_image_url

Returns the Scryfall image URL for a card dict.
card
dict
required
A card dict containing at minimum a scryfall_id key. Typically a row from the local cards table or a dict from the suggestions list.
Returns str | None — the fully-formed Scryfall image URL if scryfall_id is present and non-empty, or None if the field is missing or falsy. Callers rendering HTML should handle the None case with a placeholder element.
from card_images import card_image_url

card = {"name": "Sol Ring", "scryfall_id": "0b6d5a03-71b4-4d8e-9609-62c6fd2c5f7e"}
url = card_image_url(card)
# "https://api.scryfall.com/cards/0b6d5a03-71b4-4d8e-9609-62c6fd2c5f7e?format=image&version=normal"

build_comparison_html

Generates a standalone HTML page showing the original card and each suggestion in a horizontal row with price and savings captions.
original
dict
required
The local database row dict for the card being replaced. Must have name, scryfall_id, and price_usd fields. Used to render the left-hand card block and to calculate the savings percentage for each suggestion caption.
suggestions
list
required
A list of suggestion dicts as returned by suggest_alternatives(). Each dict must have a "card" key (the candidate row dict with name, scryfall_id, and price_usd) and a "score" key (the numeric similarity score).
Returns str — a complete, self-contained HTML document as a string. The page uses an inline <style> block (dark background, flex layout) and no external dependencies, so it renders correctly even without internet access — though the card images themselves require a live connection to Scryfall’s CDN. Each suggestion caption shows the candidate’s name, USD price, percentage savings over the original, and the similarity score. An arrow () separates the original block from the suggestion blocks.
from card_images import build_comparison_html

html = build_comparison_html(original_card, suggestions)
with open("output.html", "w", encoding="utf-8") as f:
    f.write(html)

open_comparison

Writes the comparison HTML to disk and opens it in the system’s default web browser.
original
dict
required
The local database row dict for the card being replaced. Forwarded to build_comparison_html().
suggestions
list
required
List of suggestion dicts from suggest_alternatives(). Forwarded to build_comparison_html().
path
str
default:"./data/compare.html"
File path where the HTML should be written. The parent directory is created automatically with mkdir(parents=True, exist_ok=True). The file is overwritten on each call.
Returns None. After writing the file, calls webbrowser.open() with the resolved file:// URI. This opens the default browser on macOS, Windows, and most Linux desktops. In headless environments the call silently does nothing. This function is triggered interactively when the user presses i in the terminal pipeline to inspect a specific card replacement.
from card_images import open_comparison
from scoring import load_candidate_pool, suggest_alternatives

pool = load_candidate_pool("commander")
suggestions = suggest_alternatives(original_card, pool, top_n=5)

# Writes ./data/compare.html and opens it in the browser
open_comparison(original_card, suggestions)

# Write to a custom path instead
open_comparison(original_card, suggestions, path="./output/my_comparison.html")

Build docs developers (and LLMs) love