[ka2] fix connecteur mercille: retry (3 essais, backoff 5/10 s) de la page liste — un raté transitoire (vu 2026-08-29 ~23:20) produisait un faux « 0 trouvé ok » (médiane 8) car fetch() avalait les exceptions et retournait [] si la table .table-listings manquait; après 3 essais infructueux le connecteur lève une erreur franche au lieu d'un zéro silencieux. Testé: run.py sync mercille → 8 annonces (= médiane 8)
1 changed file +20 −7
modified
louka/connectors/mercille.py
+20 −7
@@ -16,6 +16,7 @@ from __future__ import annotations | ||
| 16 | 16 | |
| 17 | 17 | import hashlib |
| 18 | 18 | import re |
| 19 | +import time | |
| 19 | 20 | |
| 20 | 21 | from bs4 import BeautifulSoup |
| 21 | 22 | |
@@ -43,15 +44,27 @@ class MercilleConnector(BaseConnector): | ||
| 43 | 44 | request_delay = 0.6 |
| 44 | 45 | |
| 45 | 46 | def fetch(self) -> list[Listing]: |
| 47 | + # Un raté transitoire de la page liste (vu 2026-08-29 ~23:20) | |
| 48 | + # produisait un faux « 0 trouvé ok » : retry court (backoff 5/10 s), | |
| 49 | + # puis erreur franche plutôt qu'un zéro silencieux. | |
| 46 | 50 | listings: list[Listing] = [] |
| 47 | − try: | |
| 48 | − html = self.get(LIST_URL).text | |
| 49 | − except Exception: | |
| 50 | − return listings | |
| 51 | − soup = BeautifulSoup(html, "html.parser") | |
| 52 | − table = soup.select_one("table.table-listings") | |
| 51 | + table = None | |
| 52 | + for attempt in range(3): | |
| 53 | + try: | |
| 54 | + html = self.get(LIST_URL).text | |
| 55 | + except Exception: | |
| 56 | + if attempt == 2: | |
| 57 | + raise | |
| 58 | + else: | |
| 59 | + soup = BeautifulSoup(html, "html.parser") | |
| 60 | + table = soup.select_one("table.table-listings") | |
| 61 | + if table is not None: | |
| 62 | + break | |
| 63 | + if attempt < 2: | |
| 64 | + time.sleep(5 * (attempt + 1)) | |
| 53 | 65 | if table is None: |
| 54 | − return listings | |
| 66 | + raise RuntimeError( | |
| 67 | + "table .table-listings introuvable après 3 essais") | |
| 55 | 68 | |
| 56 | 69 | seen: dict[str, int] = {} |
| 57 | 70 | for tr in table.select("tbody tr"): |
| 58 | 71 | |