diff --git a/backend/import_setlists_smart.py b/backend/import_setlists_smart.py index 2920cf6..dc01f57 100644 --- a/backend/import_setlists_smart.py +++ b/backend/import_setlists_smart.py @@ -56,18 +56,29 @@ def main(): matched_count = 0 page = 1 + seen_ids_in_run = set() + while True: # Fetch batch of shows print(f" Fetching shows page {page}...", end="\r", flush=True) data = fetch_json("shows", {"page": page}) # Fetch all shows (artist filter can be flaky) if not data: break - + + # Check for API loop (if Page X returns same content as Page 1) + first_id_in_batch = data[0].get('show_id') if data else None + if first_id_in_batch and first_id_in_batch in seen_ids_in_run: + print(f"\n Loop detected at page {page} (ID {first_id_in_batch} seen before). Breaking.") + break + for s in data: # We only need Goose shows (artist_id=3 usually, but we check date match) s_date = s.get('showdate') s_id = s.get('show_id') + if s_id: + seen_ids_in_run.add(s_id) + if s_date and s_id: db_id = date_to_db_id.get(s_date) if db_id: