Save inventory to JSON file with proper formatting. Converts ShapeData objects to dictionaries for JSON serialization.
(inventory: InventoryData, output_path: Path)
| 1001 | |
| 1002 | |
| 1003 | def save_inventory(inventory: InventoryData, output_path: Path) -> None: |
| 1004 | """Save inventory to JSON file with proper formatting. |
| 1005 | |
| 1006 | Converts ShapeData objects to dictionaries for JSON serialization. |
| 1007 | """ |
| 1008 | # Convert ShapeData objects to dictionaries |
| 1009 | json_inventory: InventoryDict = {} |
| 1010 | for slide_key, shapes in inventory.items(): |
| 1011 | json_inventory[slide_key] = { |
| 1012 | shape_key: shape_data.to_dict() for shape_key, shape_data in shapes.items() |
| 1013 | } |
| 1014 | |
| 1015 | with open(output_path, "w", encoding="utf-8") as f: |
| 1016 | json.dump(json_inventory, f, indent=2, ensure_ascii=False) |
| 1017 | |
| 1018 | |
| 1019 | if __name__ == "__main__": |