diff --git a/src/client.py b/src/client.py index e007173..bd1fdbc 100644 --- a/src/client.py +++ b/src/client.py @@ -159,6 +159,8 @@ def fetch_calendar(self, start_date: date, end_date: date) -> List[Tournament]: continue title = h3_tag.text.strip() + if title.startswith("Limited"): + continue event_url = urljoin(MTGO_ROOT_URL, a_tag.get("href", "")) date_str = time_tag.get("datetime", "") diff --git a/src/config.py b/src/config.py index 5a3a411..64170c3 100644 --- a/src/config.py +++ b/src/config.py @@ -12,6 +12,7 @@ "Vintage", "Pauper", "Commander", + "Premodern", ] SCRYFALL_BULK_URL = "https://api.scryfall.com/bulk-data" diff --git a/src/scraper.py b/src/scraper.py index 5e9e524..7edcd18 100644 --- a/src/scraper.py +++ b/src/scraper.py @@ -134,6 +134,11 @@ def _sync_tournament( if not t.date: t.date = today + if t.name and t.name.startswith("Limited"): + logger.info("Skipping Limited event: %s", t.name) + stats["skipped"] += 1 + return True + safe_filename = sanitize_filename(t.json_file or "unknown.json") target_dir = os.path.join( self.cache_root, diff --git a/tests/test_client.py b/tests/test_client.py index ee52bed..21e405d 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -132,6 +132,12 @@ def test_tournament_from_url(): t_duel = tournament_from_url(duel_url) assert t_duel.formats == "Commander" + premodern_url = ( + "https://www.mtgo.com/decklist/premodern-challenge-32-2026-09-1012854063" + ) + t_premodern = tournament_from_url(premodern_url) + assert t_premodern.formats == "Premodern" + def test_fetch_event_data_404_no_retry(): client = MTGOClient(max_retries=3) @@ -164,3 +170,41 @@ def test_fetch_event_data_with_request_delay(monkeypatch): client.fetch_event_data("https://www.mtgo.com/decklist/test") assert sleep_calls == [0.1] + + +def test_fetch_calendar_skips_limited_events(): + client = MTGOClient() + mock_resp = MagicMock() + mock_resp.status_code = 200 + mock_resp.text = """ + + +
  • + +

    Modern Challenge 64

    + +
    +
  • +
  • + +

    Limited Super Qualifier

    + +
    +
  • +
  • + +

    Premodern Challenge 32

    + +
    +
  • + + + """ + client.session.get = MagicMock(return_value=mock_resp) + + tournaments = client.fetch_calendar(date(2026, 9, 1), date(2026, 9, 30)) + assert len(tournaments) == 2 + assert tournaments[0].name == "Modern Challenge 64" + assert tournaments[0].formats == "Modern" + assert tournaments[1].name == "Premodern Challenge 32" + assert tournaments[1].formats == "Premodern" diff --git a/tests/test_incremental.py b/tests/test_incremental.py index e2df4e0..9b73c67 100644 --- a/tests/test_incremental.py +++ b/tests/test_incremental.py @@ -173,6 +173,24 @@ def test_sync_specified_tournaments(tmp_path): assert mock_client.fetch_calendar.call_count == 0 +def test_sync_skips_limited_event(tmp_path): + mock_client = MagicMock() + limited_tournament = Tournament( + date=date(2026, 9, 10), + name="Limited Super Qualifier", + uri="https://www.mtgo.com/decklist/limited-super-qualifier-2024-06-0912645816", + formats=None, + json_file="limited-super-qualifier-2024-06-0912645816.json", + ) + engine = MTGOSyncEngine(cache_root=str(tmp_path), client=mock_client) + stats = engine.sync(tournaments=[limited_tournament]) + + assert stats["skipped"] == 1 + assert stats["created"] == 0 + assert stats["failed"] == 0 + assert mock_client.fetch_event_data.call_count == 0 + + def test_cli_parse_retry_args(monkeypatch): from src.cli import parse_args