Spaces:
Paused
Paused
CBV01 commited on
Commit ·
2001775
1
Parent(s): e64eb90
Fix scrape yield
Browse files- backend/main.py +13 -2
backend/main.py
CHANGED
|
@@ -1325,8 +1325,19 @@ async def _scrape_telegram_search(base_query: str, rows: list, queue: Optional[a
|
|
| 1325 |
except Exception as q_err:
|
| 1326 |
err_str = str(q_err).lower()
|
| 1327 |
if "flood" in err_str or "wait" in err_str:
|
| 1328 |
-
|
| 1329 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1330 |
else:
|
| 1331 |
print(f"SCRAPER[telegram] query='{q}' acc={acc_phone} err: {q_err}")
|
| 1332 |
continue
|
|
|
|
| 1325 |
except Exception as q_err:
|
| 1326 |
err_str = str(q_err).lower()
|
| 1327 |
if "flood" in err_str or "wait" in err_str:
|
| 1328 |
+
# Extract the required wait seconds from Telethon error (e.g. "A wait of 34 seconds is required")
|
| 1329 |
+
import re
|
| 1330 |
+
match = re.search(r'wait of (\d+)', err_str)
|
| 1331 |
+
wait_sec = int(match.group(1)) if match else 5
|
| 1332 |
+
|
| 1333 |
+
# Cap extreme waits so stream doesn't infinitely hang, but wait out the standard 5-60s bans
|
| 1334 |
+
if wait_sec > 60:
|
| 1335 |
+
print(f"SCRAPER[telegram] acc={acc_phone} hit HUGE {wait_sec}s FloodWait. Skipping to next account.")
|
| 1336 |
+
break
|
| 1337 |
+
|
| 1338 |
+
print(f"SCRAPER[telegram] acc={acc_phone} hit {wait_sec}s FloodWait on '{q}', pausing then continuing...")
|
| 1339 |
+
await asyncio.sleep(wait_sec + 1)
|
| 1340 |
+
continue # DO NOT BREAK! Continue the 50 variations to hit max yield!
|
| 1341 |
else:
|
| 1342 |
print(f"SCRAPER[telegram] query='{q}' acc={acc_phone} err: {q_err}")
|
| 1343 |
continue
|