From 7353886d9bff442e4a667eadcd3caa753ef9c980 Mon Sep 17 00:00:00 2001 From: frabad Date: Wed, 18 May 2022 18:55:36 +0200 Subject: [PATCH] =?UTF-8?q?docstrings=20+=20correction=20du=20nom=20de=20d?= =?UTF-8?q?oc=20trait=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittleBock/export.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/LittleBock/export.py b/LittleBock/export.py index 258a21e..dcf141a 100755 --- a/LittleBock/export.py +++ b/LittleBock/export.py @@ -1,14 +1,16 @@ #!/usr/bin/python3 """ -exportation de données iSpindel JSON vers données CSV +exportation de données iSpindel JSON vers données applaties CSV """ -import json, pathlib, csv +import csv +import json +import pathlib class Frame(object): - """""" + """un cadre de données""" def __init__(self,fname): - """""" + """constructeur""" with open(fname,'r') as f: self._json = json.load(f) self.names = tuple(self._names()) @@ -16,20 +18,20 @@ class Frame(object): self.rows = tuple(self._rows()) def _names(self): - """""" + """génère une liste de noms""" for group in self._json: yield group["name"] def _keys(self): - """""" + """génère un liste de clés""" for i in self._json[0]["data"]: yield i["x"] def _rows(self): - """""" + """génère les lignes d'un tableau""" def row(key): - """""" + """génère une ligne d'un tableau""" for name in self.names: yield self.get(name,key) @@ -37,7 +39,7 @@ class Frame(object): yield tuple(row(k)) def get(self,name,key): - """""" + """récupère la valeur d'une entrée d'après son nom et sa clé""" for group in self._json: if group["name"] == name: for value in group["data"]: @@ -46,16 +48,18 @@ class Frame(object): if __name__ == "__main__": here = pathlib.Path.cwd() - docs = tuple(here.rglob("2.json")) + docs = tuple(here.rglob("*.json")) if len(docs) == 0: print("Aucun fichier JSON ('.json') trouvé.") - for doc in docs: + for doc_i in docs: frame = None - if doc.exists() and doc.stat().st_size > 0: - frame = Frame(doc) - with open(doc.with_suffix(".csv"),'w', newline='') as f: + if doc_i.exists() and doc_i.stat().st_size > 0: + frame = Frame(doc_i) + doc_o = doc_i.with_suffix(".csv") + with open(doc_o,'w', newline='') as f: writer = csv.writer(f,dialect='unix') writer.writerow(frame.names) writer.writerows(frame.rows) + print(f"INFO: {doc_i.name} >> {doc_o.name}")