full json

develop
gwen 3 years ago
parent f5d065dbd3
commit 6d0e19ae94

@ -16,7 +16,7 @@ bourbon_json:
folderpath: data/01_raw/houses/bourbon folderpath: data/01_raw/houses/bourbon
bourbon_jsonoutput: bourbon_jsonoutput:
type: actesdataset.JSONDataSetCollection type: actesdataset.FullJSONDataSetCollection
housename: bourbon housename: bourbon
folderpath: data/02_intermediate/houses/bourbon/json folderpath: data/02_intermediate/houses/bourbon/json

@ -61,3 +61,4 @@ def parse_json_collection(datasetcol: JSONDataSetCollection) -> Dict[str, BsXMLD
output_datasets[dataset_filenamestem] = output_xmldataset output_datasets[dataset_filenamestem] = output_xmldataset
return output_datasets return output_datasets
#def add_xmlcontent_tojson(jsondoc: JSONDataSetCollection, xmlcontent: XMLDataSetCollection) ->

@ -158,11 +158,36 @@ class JSONDataSetCollection(DataSetCollection):
filepath=str(filepath)) filepath=str(filepath))
return self return self
class JSONDataSet(AbstractDataSet):
def __init__(self, filepath: str):
self._filepath = filepath
def _load(self) -> Dict:
with open(self._filepath, 'r') as fp:
return json.load(fp)
def _save(self, data: Dict) -> None:
with open(self._filepath, 'w') as fp:
json.dump(data, fp, sort_keys=True, indent=4)
def _describe(self) -> Dict[str, Any]:
return dict(filepath=self._filepath)
class FullJSONDataSetCollection(DataSetCollection):
def _load(self) -> dict[str, JSONDataSet]:
"kedro's API loader method"
self.datasets = dict()
for filepath in sorted(self._folderpath.glob("*.xml")):
self.datasets[filepath.stem] = JSONDataSet(
filepath=str(filepath))
return self
#class TextDataSet: #class TextDataSet:
# """loads/saves data from/to a text file using an underlying filesystem # """loads/saves data from/to a text file using an underlying filesystem
# example usage # example usage
# >>> string_to_write = "This will go in a file." # >>> string_to_write = "This will go in a file."
# >>> # >>>
# >>> data_set = TextDataSet(filepath="test.md") # >>> data_set = TextDataSet(filepath="test.md")
@ -183,19 +208,3 @@ class JSONDataSetCollection(DataSetCollection):
# def _describe(self) -> Dict[str, Any]: # def _describe(self) -> Dict[str, Any]:
# return dict(filepath=self._filepath) # return dict(filepath=self._filepath)
#class JSONDataSet(AbstractDataSet):
# def __init__(self, filepath: str):
# self._filepath = filepath
# def _load(self) -> Dict:
# with open(self._filepath, 'r') as fp:
# return json.load(fp)
# def _save(self, data: Dict) -> None:
# with open(self._filepath, 'w') as fp:
# json.dump(data, fp, sort_keys=True, indent=4)
# def _describe(self) -> Dict[str, Any]:
# return dict(filepath=self._filepath)

Loading…
Cancel
Save