Fix infinite loop in import script

This commit is contained in:
fullsizemalt 2025-12-25 11:44:49 -08:00
parent 14f016977a
commit 29e3e07141

View file

@ -56,18 +56,29 @@ def main():
matched_count = 0 matched_count = 0
page = 1 page = 1
seen_ids_in_run = set()
while True: while True:
# Fetch batch of shows # Fetch batch of shows
print(f" Fetching shows page {page}...", end="\r", flush=True) print(f" Fetching shows page {page}...", end="\r", flush=True)
data = fetch_json("shows", {"page": page}) # Fetch all shows (artist filter can be flaky) data = fetch_json("shows", {"page": page}) # Fetch all shows (artist filter can be flaky)
if not data: if not data:
break 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: for s in data:
# We only need Goose shows (artist_id=3 usually, but we check date match) # We only need Goose shows (artist_id=3 usually, but we check date match)
s_date = s.get('showdate') s_date = s.get('showdate')
s_id = s.get('show_id') s_id = s.get('show_id')
if s_id:
seen_ids_in_run.add(s_id)
if s_date and s_id: if s_date and s_id:
db_id = date_to_db_id.get(s_date) db_id = date_to_db_id.get(s_date)
if db_id: if db_id: