Skip to content

Commit

Permalink
Separate the xml metadata json creation from the saving to FS
Browse files Browse the repository at this point in the history
  • Loading branch information
benbart committed Sep 29, 2023
1 parent 6f965d8 commit a009ca0
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/index_safe/create_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,26 @@ def create_index(
return bursts


def xml_metadata_as_json(entries: Iterable[utils.XmlMetadata]) -> str:
"""Creates a list of XmlMetadata objects as json.
Args:
entries: List of metadata objects to be included
Returns:
JSON string of metadata
"""
slc = entries[0].slc
metadata_dicts = [entry.to_dict()[slc] for entry in entries]
combined_dict = {}
for metadata_dict in metadata_dicts:
combined_dict.update(metadata_dict)

return json.dumps({slc: combined_dict})


def save_xml_metadata_as_json(entries: Iterable[utils.XmlMetadata], out_name: str) -> str:
"""Save a list of XmlMetadata objects as a json.
"""Create and save a list of XmlMetadata objects as a json.
Args:
entries: List of metadata objects to be included
Expand All @@ -191,7 +209,7 @@ def save_xml_metadata_as_json(entries: Iterable[utils.XmlMetadata], out_name: st
combined_dict.update(metadata_dict)

with open(out_name, 'w') as json_file:

Check failure on line 211 in src/index_safe/create_index.py

View workflow job for this annotation

GitHub Actions / check-with-ruff

Ruff (F841)

src/index_safe/create_index.py:211:33: F841 Local variable `json_file` is assigned to but never used

Check failure on line 211 in src/index_safe/create_index.py

View workflow job for this annotation

GitHub Actions / check-with-ruff

Ruff (F841)

src/index_safe/create_index.py:211:33: F841 Local variable `json_file` is assigned to but never used
json.dump({slc: combined_dict}, json_file)
xml_metadata_as_json(entries)
return out_name


Expand Down

0 comments on commit a009ca0

Please sign in to comment.