Reducing image count

This commit is contained in:
2026-07-17 19:47:51 -04:00
parent e64193639e
commit 8690334a80
1203 changed files with 2 additions and 291 deletions
-19
View File
@@ -66,25 +66,6 @@ foreach (var file in mdFiles)
cards.Add(card);
}
// Copy PNGs to wwwroot/cards
var cardsDir = Path.Combine(webWwwRoot, "cards");
Directory.CreateDirectory(cardsDir);
var pngFiles = Directory.GetFiles(docsDir, "*.png", SearchOption.AllDirectories);
var pngMap = pngFiles
.GroupBy(Path.GetFileName)
.ToDictionary(g => g.Key!, g => g.First(), StringComparer.OrdinalIgnoreCase);
foreach (var card in cards)
{
if (card.ImageFile == null) continue;
if (pngMap.TryGetValue(card.ImageFile, out var src))
{
var dst = Path.Combine(cardsDir, card.ImageFile);
File.Copy(src, dst, true);
}
}
// Generate C# source file
Directory.CreateDirectory(Path.GetDirectoryName(generatedFile)!);
using var writer = new StreamWriter(generatedFile, false, Encoding.UTF8);
-138
View File
@@ -1,138 +0,0 @@
import os
import re
import requests
import time
from concurrent.futures import ThreadPoolExecutor
# Configuration
DOCS_DIR = r"..\chrono.docs"
CLOUD_CARDS_DIR = r"Cloud\wwwroot\cards"
STANDALONE_CARDS_DIR = r"Standalone\wwwroot\cards"
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
def get_card_names():
card_names = []
# Search for all .md files in chrono.docs
for root, dirs, files in os.walk(DOCS_DIR):
for file in files:
if file.endswith(".md"):
# Remove .md extension
card_names.append(file[:-3])
return card_names
def slugify(card_name):
# Manual overrides for slugs that don't follow the standard pattern
overrides = {
"APEX Starcruise": "apex-starcruiser",
"Consummate Conspirator": "consomme-conspirator",
"Librarian's Assistant": "librarian-assistant",
"Violet Inquisitioner": "violet-inquisitor",
"Breakdown": "break-down",
"Da'Kad, Heretic Crusher": "da-kad-heretic-crusher",
"Shae'Fan, Remembered": "shae-fan-remembered",
"Possessed Prawn": "possessed-prawn-card",
"P.O.G.O": "p-o-g-o",
"A'kon, Starry Diviner": "a-kon-starry-diviner",
"B.O.O.F.": "b-o-o-f",
"Raiz, Pacifist's Conclusion": "raiz-pacifists-conclusion",
"Spirit's Lament": "spirits-lament",
"Overmind's Guilt": "overminds-guilt",
"Entropy's End": "entropys-end",
"Vorkon, Eternal Source": "vor-kon-eternal-source",
"Ta'kan the Tattle": "ta-kan-the-tattle",
}
# Fix potential encoding issues in card_name (e.g. smart quotes)
# If the script is run in an environment where the filenames were read as mangled
# we want to ensure we use the correct name for the filename and slug lookup.
# Note: '’' is the UTF-8 bytes for '' interpreted as Windows-1252
if isinstance(card_name, str):
card_name = card_name.replace("’", "'").replace("", "'")
if card_name in overrides:
return overrides[card_name]
# Convert to lowercase, replace spaces/special chars with hyphens
slug = card_name.lower()
slug = re.sub(r'[^a-z0-9]+', '-', slug)
slug = slug.strip('-')
return slug
def download_full_art(card_name):
# Fix potential encoding issues in card_name (e.g. smart quotes)
if isinstance(card_name, str):
card_name = card_name.replace("’", "'").replace("", "'")
slug = slugify(card_name)
url = f"https://www.playchrono.com/card/{slug}"
print(f"Processing {card_name} ({url})...")
try:
response = requests.get(url, headers={"User-Agent": USER_AGENT}, timeout=10)
if response.status_code != 200:
print(f" [ERROR] Failed to fetch page for {card_name}: {response.status_code}")
return
# Look for all data-lightbox-src and data-lightbox-alt pairs
# We want the ones that end with "Full Art" and match our card name
pattern = r'data-lightbox-src="([^"]+)"\s+data-lightbox-alt="([^"]+)"'
matches = re.findall(pattern, response.text)
full_art_url = None
for src, alt in matches:
if "Full Art" in alt and (card_name.lower() in alt.lower()):
full_art_url = src
break
# Fallback to the first "Full Art" if no exact match (sometimes names might slightly differ)
if not full_art_url:
for src, alt in matches:
if "Full Art" in alt:
full_art_url = src
break
# Absolute fallback to any data-lightbox-src with the pattern if still nothing
if not full_art_url:
match = re.search(r'data-lightbox-src="(https://cdn\.playchrono\.com/latest/en_us/img/cards/set/1/[^"]+\.png)"', response.text)
if match:
full_art_url = match.group(1)
if not full_art_url:
print(f" [INFO] No full art found for {card_name}")
return
print(f" [FOUND] {full_art_url} for {card_name}")
# Download image
img_response = requests.get(full_art_url, headers={"User-Agent": USER_AGENT}, timeout=10)
if img_response.status_code == 200:
filename = f"fa{card_name}.png"
# Save to Cloud
os.makedirs(CLOUD_CARDS_DIR, exist_ok=True)
with open(os.path.join(CLOUD_CARDS_DIR, filename), "wb") as f:
f.write(img_response.content)
# Save to Standalone
os.makedirs(STANDALONE_CARDS_DIR, exist_ok=True)
with open(os.path.join(STANDALONE_CARDS_DIR, filename), "wb") as f:
f.write(img_response.content)
print(f" [SUCCESS] Saved {filename}")
else:
print(f" [ERROR] Failed to download image for {card_name}: {img_response.status_code}")
except Exception as e:
print(f" [ERROR] Exception for {card_name}: {e}")
def main():
card_names = get_card_names()
print(f"Found {len(card_names)} cards to process.")
# Use ThreadPoolExecutor for faster downloads
with ThreadPoolExecutor(max_workers=5) as executor:
executor.map(download_full_art, card_names)
if __name__ == "__main__":
main()
-133
View File
@@ -1,133 +0,0 @@
"""
One-time script: Download card images from playchrono.com and add imageLink frontmatter.
Usage:
python process_cards.py
Requires a saved HTML copy of https://www.playchrono.com/collections/cards
with the embedded JSON.parse('...') card data.
"""
import re
import json
import os
import urllib.request
import sys
# Adjust these paths for your environment
html_file = r"../playchrono_cards_page.html"
docs_dir = r"../../chrono.docs"
if not os.path.exists(html_file):
# Fallback: search for saved tool output
possible = [f for f in os.listdir(r"C:\Users\jonmc\.local\share\opencode\tool-output")
if f.startswith("tool_") and os.path.isfile(os.path.join(r"C:\Users\jonmc\.local\share\opencode\tool-output", f))]
if possible:
html_file = os.path.join(r"C:\Users\jonmc\.local\share\opencode\tool-output", possible[-1])
with open(html_file, 'r', encoding='utf-8') as f:
html = f.read()
start_marker = "JSON.parse('"
idx = html.find(start_marker)
if idx < 0:
print("ERROR: Could not find JSON.parse in HTML")
sys.exit(1)
start = idx + len(start_marker)
quote_end = html.find("')", start)
if quote_end < 0:
print("ERROR: Could not find closing '")
sys.exit(1)
raw_json_str = html[start:quote_end]
json_str = raw_json_str.encode('utf-8').decode('unicode_escape')
json_str = json_str.replace('\\/', '/')
try:
cards = json.loads(json_str)
except json.JSONDecodeError as e:
print(f"ERROR parsing JSON: {e}")
sys.exit(1)
print(f"Found {len(cards)} cards")
name_to_image = {}
for card in cards:
name = card.get('name', '')
image_url = card.get('image_url', '')
if name and image_url:
name_to_image[name.lower()] = image_url
counterpart = card.get('counterpart')
if counterpart and isinstance(counterpart, dict):
cname = counterpart.get('name', '')
cimage = counterpart.get('image_url', '')
if cname and cimage:
name_to_image[cname.lower()] = cimage
print(f"Built mapping for {len(name_to_image)} card names")
md_files = [f for f in os.listdir(docs_dir) if f.endswith('.md')]
print(f"Found {len(md_files)} markdown files")
processed = 0
downloaded = 0
matched = 0
for md_file in sorted(md_files):
filepath = os.path.join(docs_dir, md_file)
card_name = md_file[:-3]
card_name_lower = card_name.lower()
if card_name_lower not in name_to_image:
continue
matched += 1
image_url = name_to_image[card_name_lower]
png_filename = f"{card_name}.png"
png_filepath = os.path.join(docs_dir, png_filename)
if not os.path.exists(png_filepath):
try:
print(f" DL: {png_filename}")
req = urllib.request.Request(image_url, headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36'
})
with urllib.request.urlopen(req) as response:
with open(png_filepath, 'wb') as out:
out.write(response.read())
downloaded += 1
except Exception as e:
print(f" ERR: {png_filename} - {e}")
continue
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
has_image_link = 'imageLink:' in content
img_ref = f"![[{png_filename}]]"
has_img_ref = img_ref in content
if has_image_link and has_img_ref:
continue
modified = content
if not has_image_link:
modified = modified.rstrip()
if modified.endswith('---'):
modified = modified[:-3] + f'imageLink: "[[{png_filename}]]"\n---'
else:
modified = modified + f'\nimageLink: "[[{png_filename}]]"\n'
if not has_img_ref:
modified = modified.rstrip() + f'\n\n\n{img_ref}\n'
with open(filepath, 'w', encoding='utf-8') as f:
f.write(modified)
processed += 1
print(f"\nDone! Matched: {matched}, Downloaded: {downloaded}, Updated markdown: {processed}")
print(f"Skipped (no card match): {len(md_files) - matched}")
Binary file not shown.

Before

Width:  |  Height:  |  Size: 157 KiB

After

Width:  |  Height:  |  Size: 434 KiB

Before

Width:  |  Height:  |  Size: 560 KiB

After

Width:  |  Height:  |  Size: 560 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 KiB

After

Width:  |  Height:  |  Size: 656 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 KiB

After

Width:  |  Height:  |  Size: 568 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 115 KiB

After

Width:  |  Height:  |  Size: 243 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 213 KiB

After

Width:  |  Height:  |  Size: 808 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 141 KiB

After

Width:  |  Height:  |  Size: 386 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 KiB

After

Width:  |  Height:  |  Size: 573 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 KiB

After

Width:  |  Height:  |  Size: 532 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 KiB

After

Width:  |  Height:  |  Size: 514 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 KiB

After

Width:  |  Height:  |  Size: 843 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 220 KiB

After

Width:  |  Height:  |  Size: 12 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 151 KiB

After

Width:  |  Height:  |  Size: 603 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 KiB

After

Width:  |  Height:  |  Size: 571 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

After

Width:  |  Height:  |  Size: 380 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 360 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 145 KiB

After

Width:  |  Height:  |  Size: 449 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 KiB

After

Width:  |  Height:  |  Size: 275 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 189 KiB

After

Width:  |  Height:  |  Size: 621 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 138 KiB

After

Width:  |  Height:  |  Size: 398 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 130 KiB

After

Width:  |  Height:  |  Size: 397 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 158 KiB

After

Width:  |  Height:  |  Size: 548 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

After

Width:  |  Height:  |  Size: 582 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 127 KiB

After

Width:  |  Height:  |  Size: 425 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

After

Width:  |  Height:  |  Size: 524 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 KiB

After

Width:  |  Height:  |  Size: 584 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 170 KiB

After

Width:  |  Height:  |  Size: 691 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 146 KiB

After

Width:  |  Height:  |  Size: 446 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 162 KiB

After

Width:  |  Height:  |  Size: 570 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

After

Width:  |  Height:  |  Size: 493 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 137 KiB

After

Width:  |  Height:  |  Size: 531 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

After

Width:  |  Height:  |  Size: 515 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 123 KiB

After

Width:  |  Height:  |  Size: 410 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 KiB

After

Width:  |  Height:  |  Size: 583 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 131 KiB

After

Width:  |  Height:  |  Size: 432 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 KiB

After

Width:  |  Height:  |  Size: 551 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 131 KiB

After

Width:  |  Height:  |  Size: 536 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 152 KiB

After

Width:  |  Height:  |  Size: 418 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

After

Width:  |  Height:  |  Size: 512 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 167 KiB

After

Width:  |  Height:  |  Size: 611 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 KiB

After

Width:  |  Height:  |  Size: 577 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 466 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

After

Width:  |  Height:  |  Size: 586 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 166 KiB

After

Width:  |  Height:  |  Size: 630 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 145 KiB

After

Width:  |  Height:  |  Size: 515 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 147 KiB

After

Width:  |  Height:  |  Size: 517 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 114 KiB

After

Width:  |  Height:  |  Size: 511 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 191 KiB

After

Width:  |  Height:  |  Size: 588 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

After

Width:  |  Height:  |  Size: 564 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 247 KiB

After

Width:  |  Height:  |  Size: 706 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 169 KiB

After

Width:  |  Height:  |  Size: 571 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 549 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 138 KiB

After

Width:  |  Height:  |  Size: 562 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 133 KiB

After

Width:  |  Height:  |  Size: 509 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 177 KiB

After

Width:  |  Height:  |  Size: 551 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 154 KiB

After

Width:  |  Height:  |  Size: 544 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 184 KiB

After

Width:  |  Height:  |  Size: 654 KiB

Before

Width:  |  Height:  |  Size: 689 KiB

After

Width:  |  Height:  |  Size: 689 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 170 KiB

After

Width:  |  Height:  |  Size: 567 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 KiB

After

Width:  |  Height:  |  Size: 428 KiB

Before

Width:  |  Height:  |  Size: 477 KiB

After

Width:  |  Height:  |  Size: 477 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 151 KiB

After

Width:  |  Height:  |  Size: 480 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 158 KiB

After

Width:  |  Height:  |  Size: 484 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 KiB

After

Width:  |  Height:  |  Size: 542 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 175 KiB

After

Width:  |  Height:  |  Size: 443 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 KiB

After

Width:  |  Height:  |  Size: 398 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 141 KiB

After

Width:  |  Height:  |  Size: 479 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 213 KiB

After

Width:  |  Height:  |  Size: 799 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 KiB

After

Width:  |  Height:  |  Size: 376 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 177 KiB

After

Width:  |  Height:  |  Size: 538 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 KiB

After

Width:  |  Height:  |  Size: 797 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 147 KiB

After

Width:  |  Height:  |  Size: 415 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 131 KiB

After

Width:  |  Height:  |  Size: 525 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 141 KiB

After

Width:  |  Height:  |  Size: 493 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 125 KiB

After

Width:  |  Height:  |  Size: 466 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 KiB

After

Width:  |  Height:  |  Size: 649 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 163 KiB

After

Width:  |  Height:  |  Size: 401 KiB

Before

Width:  |  Height:  |  Size: 446 KiB

After

Width:  |  Height:  |  Size: 446 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 172 KiB

After

Width:  |  Height:  |  Size: 592 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

After

Width:  |  Height:  |  Size: 450 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 125 KiB

After

Width:  |  Height:  |  Size: 404 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 KiB

After

Width:  |  Height:  |  Size: 856 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 163 KiB

After

Width:  |  Height:  |  Size: 623 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 149 KiB

After

Width:  |  Height:  |  Size: 444 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 557 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 KiB

After

Width:  |  Height:  |  Size: 414 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 154 KiB

After

Width:  |  Height:  |  Size: 625 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 175 KiB

After

Width:  |  Height:  |  Size: 579 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 143 KiB

After

Width:  |  Height:  |  Size: 571 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 130 KiB

After

Width:  |  Height:  |  Size: 504 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 121 KiB

After

Width:  |  Height:  |  Size: 348 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 193 KiB

After

Width:  |  Height:  |  Size: 646 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 157 KiB

After

Width:  |  Height:  |  Size: 453 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 135 KiB

After

Width:  |  Height:  |  Size: 474 KiB

Before

Width:  |  Height:  |  Size: 582 KiB

After

Width:  |  Height:  |  Size: 582 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 181 KiB

After

Width:  |  Height:  |  Size: 566 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 158 KiB

After

Width:  |  Height:  |  Size: 595 KiB

Some files were not shown because too many files have changed in this diff Show More