Compare commits

..

No commits in common. "c9bc3077119b1d3f68eaac70f9f3e054bd93e8d9" and "a108d34b375c952a341f71b365bcca4f250950af" have entirely different histories.

2 changed files with 14 additions and 20 deletions

2
.gitignore vendored
View File

@ -1,6 +1,4 @@
local/
*.tar.gz
*.tar.xz
*.json
*.csv

View File

@ -1,16 +1,14 @@
#!/usr/bin/python3
"""
exportation de données iSpindel JSON vers données applaties CSV
exportation de données iSpindel JSON vers données CSV
"""
import csv
import json
import pathlib
import json, pathlib, csv
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())
@ -18,20 +16,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)
@ -39,7 +37,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"]:
@ -48,18 +46,16 @@ class Frame(object):
if __name__ == "__main__":
here = pathlib.Path.cwd()
docs = tuple(here.rglob("*.json"))
docs = tuple(here.rglob("2.json"))
if len(docs) == 0:
print("Aucun fichier JSON ('.json') trouvé.")
for doc_i in docs:
for doc in docs:
frame = None
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:
if doc.exists() and doc.stat().st_size > 0:
frame = Frame(doc)
with open(doc.with_suffix(".csv"),'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}")