Supports Flexible YAML paths from parent directory
This commit is contained in:
parent
74e22e7b60
commit
1d23b34ad6
5 changed files with 16 additions and 4 deletions
|
|
@ -6,7 +6,7 @@ import os
|
|||
@dataclass(frozen=True)
|
||||
class Constants:
|
||||
|
||||
DB_VERSION_THIS_APP_WANTS = 2
|
||||
DB_VERSION_THIS_APP_WANTS = 1
|
||||
|
||||
# ticketing group:
|
||||
TICKET_API_BASE_URL: Final[str] = os.environ.get(
|
||||
|
|
|
|||
|
|
@ -27,11 +27,10 @@ def extract_from_nested(obj, yaml_keys, default=None):
|
|||
This function removes unnecessary nesting,
|
||||
by comparing it to a pre-made YAML mapping
|
||||
"""
|
||||
def denormalize(data, which_yaml_file):
|
||||
def denormalize(data, mapping_file):
|
||||
final_results = []
|
||||
|
||||
# prep the mapping config:
|
||||
mapping_file = f"assets/yaml_mappings/{which_yaml_file}"
|
||||
with open(mapping_file) as f:
|
||||
mapping = yaml.safe_load(f)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ from core.models.orm_models.Base import Base
|
|||
from core.observers.ClientObserver import ClientObserver
|
||||
from core.observers.ConnectionObserver import ConnectionObserver
|
||||
from core.errors.logger import logger
|
||||
from core.utils.basic_operations.get_parent_directory import get_parent_directory
|
||||
|
||||
from typing import Optional
|
||||
import json
|
||||
|
|
@ -29,8 +30,11 @@ def sync_one_orm_model(
|
|||
new_data = api_result.get("data")
|
||||
|
||||
# prep data (denormalize)
|
||||
parent_directory = get_parent_directory()
|
||||
yaml_filename = f"{which_endpoint}.yaml"
|
||||
denormalized_data = denormalize(new_data, yaml_filename)
|
||||
full_yaml_path = f"{parent_directory}/assets/yaml_mappings/{yaml_filename}"
|
||||
|
||||
denormalized_data = denormalize(new_data, str(full_yaml_path))
|
||||
|
||||
if denormalized_data:
|
||||
# Debug Pretty print with indentation
|
||||
|
|
|
|||
8
core/utils/basic_operations/get_parent_directory.py
Normal file
8
core/utils/basic_operations/get_parent_directory.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from pathlib import Path
|
||||
import core
|
||||
|
||||
def get_parent_directory():
|
||||
# Get core's parent directory
|
||||
parent_directory = Path(core.__file__).parent.parent
|
||||
|
||||
return str(parent_directory)
|
||||
|
|
@ -37,6 +37,7 @@ dependencies = [
|
|||
"pydantic_core==2.46.3",
|
||||
"pydeps==3.0.6",
|
||||
"pytokens==0.4.1",
|
||||
"PyYAML==6.0.3",
|
||||
"stdlib-list==0.12.0",
|
||||
"SQLAlchemy==2.0.51",
|
||||
"toolz==1.1.0",
|
||||
|
|
|
|||
Loading…
Reference in a new issue