Fix MTGJSON download: use .json files, remove gzip unpacking

- Changed REQUIRED_FILES to REQUIRED_JSON_FILES and REQUIRED_ZIP_FILES
- AllSetFiles.zip kept as zip (only available compressed on MTGJSON)
- All other files downloaded as .json (no compression)
- Removed gzip import and unpacking logic for .gz files
- Updated EXPECTED_MIN_SIZES to reflect actual .json file sizes
- Removed validation for non-existent files
This commit is contained in:
2026-07-20 13:59:45 +00:00
parent 2369c2cc8c
commit 3fae593a22
3 changed files with 127 additions and 109 deletions
+71
View File
@@ -0,0 +1,71 @@
#!/usr/bin/env python3
"""Test MTGJSON API endpoints and download JSON files."""
import asyncio
import aiohttp
from pathlib import Path
DATA_DIR = Path("/app/data/mtgjson")
DATA_DIR.mkdir(parents=True, exist_ok=True)
# MTGJSON API endpoints for .json files
MTGJSON_BASE_URL = "https://mtgjson.com/api/v5"
JSON_FILES = {
"AllPrintings.json": MTGJSON_BASE_URL + "/AllPrintings.json",
"AllSetFiles.json": MTGJSON_BASE_URL + "/AllSetFiles.json",
"AllIdentifiers.json": MTGJSON_BASE_URL + "/AllIdentifiers.json",
"CardTypes.json": MTGJSON_BASE_URL + "/CardTypes.json",
"DeckList.json": MTGJSON_BASE_URL + "/DeckList.json",
"Keywords.json": MTGJSON_BASE_URL + "/Keywords.json",
"SetList.json": MTGJSON_BASE_URL + "/SetList.json",
}
async def test_download_file(session, url, filename):
"""Test downloading a single JSON file."""
dest_path = DATA_DIR / filename
print(f"Testing {filename}...")
try:
async with session.get(url) as response:
if response.status == 200:
content = await response.read()
print(f" ✓ Status: {response.status}")
print(f" ✓ Size: {len(content) / (1024*1024):.2f} MB")
print(f" ✓ Content-Type: {response.content_type}")
# Write to file
with open(dest_path, 'wb') as f:
f.write(content)
print(f" ✓ Saved to {dest_path}")
# Test JSON parsing
import json
with open(dest_path, 'r', encoding='utf-8') as f:
data = json.load(f)
print(f" ✓ Valid JSON: {type(data).__name__}")
return True
else:
print(f" ✗ Status: {response.status}")
return False
except Exception as e:
print(f" ✗ Error: {e}")
return False
async def main():
"""Test all MTGJSON JSON endpoints."""
print("Testing MTGJSON JSON API endpoints...\n")
async with aiohttp.ClientSession() as session:
results = []
for filename, url in JSON_FILES.items():
success = await test_download_file(session, url, filename)
results.append((filename, success))
print()
print("\n=== Results ===")
for filename, success in results:
status = "" if success else ""
print(f"{status} {filename}")
if __name__ == "__main__":
asyncio.run(main())