Compare commits
No commits in common. "a108d34b375c952a341f71b365bcca4f250950af" and "f015641a111969ee989bec2ad86be4aebc6fa6a8" have entirely different histories.
a108d34b37
...
f015641a11
@ -7,8 +7,6 @@ import datetime
|
|||||||
"""
|
"""
|
||||||
ajoute une valeur de date lisible par un humain à chaque entrée d'un document JSON
|
ajoute une valeur de date lisible par un humain à chaque entrée d'un document JSON
|
||||||
|
|
||||||
TODO: rassembler les dates dans un groupe d'entrées
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def from_stamp(i: int) -> str:
|
def from_stamp(i: int) -> str:
|
||||||
@ -17,9 +15,10 @@ def from_stamp(i: int) -> str:
|
|||||||
if len(dt)>10:
|
if len(dt)>10:
|
||||||
dt = dt[:10]
|
dt = dt[:10]
|
||||||
sdt = str(datetime.datetime.fromtimestamp(int(dt)))
|
sdt = str(datetime.datetime.fromtimestamp(int(dt)))
|
||||||
|
#print(f" {dt} : {sdt}")
|
||||||
return sdt
|
return sdt
|
||||||
|
|
||||||
def proc(path_in):
|
def jsproc(path_in):
|
||||||
"""traite un document JSON"""
|
"""traite un document JSON"""
|
||||||
_json = None
|
_json = None
|
||||||
with open(path_in,'r') as f:
|
with open(path_in,'r') as f:
|
||||||
@ -31,12 +30,12 @@ def proc(path_in):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
here = pathlib.Path.cwd()
|
here = pathlib.Path.cwd()
|
||||||
docs = tuple(here.rglob("*.json"))
|
jsdocs = tuple(here.rglob("*.json"))
|
||||||
if len(docs) == 0:
|
if len(jsdocs) == 0:
|
||||||
print("Aucun fichier JSON ('.json') trouvé.")
|
print("Aucun fichier JSON ('.json') trouvé.")
|
||||||
for i in docs:
|
for i in jsdocs:
|
||||||
if i.exists() and i.stat().st_size > 0:
|
if i.exists() and i.stat().st_size > 0:
|
||||||
data = proc(i)
|
data = jsproc(i)
|
||||||
if data:
|
if data:
|
||||||
with open(i,'w') as f:
|
with open(i,'w') as f:
|
||||||
f.write(json.dumps(data,
|
f.write(json.dumps(data,
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
"""
|
|
||||||
exportation de données iSpindel JSON vers données CSV
|
|
||||||
"""
|
|
||||||
import json, pathlib, csv
|
|
||||||
|
|
||||||
class Frame(object):
|
|
||||||
""""""
|
|
||||||
|
|
||||||
def __init__(self,fname):
|
|
||||||
""""""
|
|
||||||
with open(fname,'r') as f:
|
|
||||||
self._json = json.load(f)
|
|
||||||
self.names = tuple(self._names())
|
|
||||||
self.keys = tuple(self._keys())
|
|
||||||
self.rows = tuple(self._rows())
|
|
||||||
|
|
||||||
def _names(self):
|
|
||||||
""""""
|
|
||||||
for group in self._json:
|
|
||||||
yield group["name"]
|
|
||||||
|
|
||||||
def _keys(self):
|
|
||||||
""""""
|
|
||||||
for i in self._json[0]["data"]:
|
|
||||||
yield i["x"]
|
|
||||||
|
|
||||||
def _rows(self):
|
|
||||||
""""""
|
|
||||||
|
|
||||||
def row(key):
|
|
||||||
""""""
|
|
||||||
for name in self.names:
|
|
||||||
yield self.get(name,key)
|
|
||||||
|
|
||||||
for k in self.keys:
|
|
||||||
yield tuple(row(k))
|
|
||||||
|
|
||||||
def get(self,name,key):
|
|
||||||
""""""
|
|
||||||
for group in self._json:
|
|
||||||
if group["name"] == name:
|
|
||||||
for value in group["data"]:
|
|
||||||
if value.get("x") == key:
|
|
||||||
return value.get("y")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
here = pathlib.Path.cwd()
|
|
||||||
docs = tuple(here.rglob("2.json"))
|
|
||||||
if len(docs) == 0:
|
|
||||||
print("Aucun fichier JSON ('.json') trouvé.")
|
|
||||||
for doc 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:
|
|
||||||
writer = csv.writer(f,dialect='unix')
|
|
||||||
writer.writerow(frame.names)
|
|
||||||
writer.writerows(frame.rows)
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user