ajout(main.py): ajout dans csv

This commit is contained in:
2026-02-11 23:58:51 +01:00
parent 011bb6a689
commit dd430b9861
3 changed files with 24 additions and 19 deletions

2
.gitignore vendored
View File

@@ -205,3 +205,5 @@ cython_debug/
marimo/_static/ marimo/_static/
marimo/_lsp/ marimo/_lsp/
__marimo__/ __marimo__/
*.csv

View File

View File

@@ -299,10 +299,11 @@ class Scraper:
except JSONDecodeError | HTTPError: except JSONDecodeError | HTTPError:
return None return None
def getvins(self, subdir: str): def getvins(self, subdir: str, filename: str):
cache: set[str] = set[str]() cache: set[str] = set[str]()
page = 0 page = 0
with open(filename, 'a') as f:
while True: while True:
page += 1 page += 1
products_list = self._geturlproductslist(f"{subdir}?page={page}") products_list = self._geturlproductslist(f"{subdir}?page={page}")
@@ -320,10 +321,12 @@ class Scraper:
if link and link not in cache: if link and link not in cache:
try: try:
infos = self.getjsondata(link).informations() infos = self.getjsondata(link).informations()
_ = f.write(infos + "\n")
print(infos) print(infos)
cache.add(link) cache.add(link)
except JSONDecodeError | HTTPError as e: except JSONDecodeError | HTTPError as e:
print(f"Erreur sur le produit {link}: {e}") print(f"Erreur sur le produit {link}: {e}")
f.flush()
# Scraper().getvins("bordeaux.html") Scraper().getvins("bordeaux.html", "donnee.csv")