puudot/code/db.py
Lauri Koskenniemi be4efa0fd2 First test version and data cleanup
Implemented code for the first test version.
Added Docker funtionality.

Define data location in compose and run:
	docker compose up

Removed test data from the repository.
2025-05-24 16:54:19 +03:00

29 lines
769 B
Python

import json
import yaml
def load_yaml(filename):
# Check file extension
if not filename.lower().endswith(('.yaml', '.yml')):
raise ValueError(f"File '{filename}' is not a YAML file")
# Read file content
with open(filename, 'r') as f:
content = f.read()
# Try to load as YAML
try:
data = yaml.safe_load(content)
if not isinstance(data, dict):
raise ValueError("YAML content does not contain a dictionary")
return data
except yaml.YAMLError as e:
raise ValueError(f"Invalid YAML format in file '{filename}': {str(e)}")
#def main():
# data = load_yaml(DATA)
# json_data = json.dumps(data, indent=2)
# print(json_data)
#if __name__ == "__main__":
# main()