forked from Olav63/outils_OSM
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import json
|
|
from pyexcel_ods3 import save_data
|
|
from collections import OrderedDict
|
|
|
|
|
|
class Save:
|
|
def as_ods(self, fields, data, dossier, nom_req):
|
|
"""Sauvegarde de data dans un classeur ods"""
|
|
|
|
ODSdataSheet = OrderedDict()
|
|
ODSdata = []
|
|
ODSdata.append(fields.keys())
|
|
index_line = 2
|
|
|
|
for element in data["elements"]:
|
|
line = []
|
|
index_col = 0
|
|
|
|
for field in fields.keys():
|
|
if field in element["tags"]:
|
|
if field == "capacity":
|
|
val = element["tags"][field]
|
|
line.append(int(val) if val.isdigit() else val)
|
|
else:
|
|
line.append(element["tags"][field])
|
|
else:
|
|
line.append("")
|
|
index_col = index_col + 1
|
|
|
|
ODSdata.append(line)
|
|
index_line = index_line + 1
|
|
|
|
ODSdataSheet.update({"resultats": ODSdata})
|
|
|
|
save_data(dossier + nom_req + ".ods", ODSdataSheet)
|
|
|
|
print("Sauvegarde résultats format ODS pour " + nom_req)
|
|
|
|
def as_json(self, export_json, dossier, nom_req):
|
|
"""Enregistrement du JSON"""
|
|
|
|
jsonFile = open(dossier + nom_req + ".json", "w")
|
|
jsonFile.write(json.dumps(export_json))
|
|
jsonFile.close()
|
|
|
|
print("Sauvegarde résultat format JSON/OSM " + nom_req)
|