From 09209b3b3e8c024d7a14d5775e5dcf1ecb28161e Mon Sep 17 00:00:00 2001 From: frabad Date: Fri, 6 May 2022 18:23:36 +0200 Subject: [PATCH] =?UTF-8?q?recherche=20r=C3=A9cursive=20des=20sources=20de?= =?UTF-8?q?=20donn=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittleBock/extract.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/LittleBock/extract.py b/LittleBock/extract.py index 49c845e..2c00a5c 100755 --- a/LittleBock/extract.py +++ b/LittleBock/extract.py @@ -5,29 +5,28 @@ extracteur de données iSpindel JSON entreposées par Little Bock en HTML import json try: import lxml.html as LX -except ModuleNotFoundError as e: +except ModuleNotFoundError: import sys - print("Le module 'lxml' est nécessaire.\n http://pypi.org/lxml") - sys.exit() + sys.exit("Le module 'lxml' est nécessaire.\n http://pypi.org/lxml") import pathlib -def proc(path): +def proc(path_in): s, js = None, None - h = LX.parse(path.name) + h = LX.parse(str(path_in)) x = h.xpath("//*[@id='fermentation_log_chart']") if x: s = x[0].get('data-chart-options') if s: - js = json.dumps( - json.loads(s).pop('series'), indent=4, sort_keys=True) or None + js = json.dumps(json.loads(s).pop('series'), indent=4, sort_keys=True + ) or None if js: - p = path.with_suffix('.json') - with open(p,'w') as f: + path_out = path_in.with_suffix('.json') + with open(path_out,'w') as f: f.write(js) - print(f"INFO: extraction des données dans {p.name}.") + print(f"INFO: {path_in.name} >> {path_out.name}") if __name__ == "__main__": here = pathlib.Path.cwd() - hdocs = tuple(here.glob("*.html")) + hdocs = tuple(here.rglob("*.html")) if len(hdocs) == 0: print("Aucun fichier HTML ('.html') trouvé.") for i in hdocs: