diff --git a/scripts/utils.py b/scripts/utils.py index 52452bd..d49401f 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -1,4 +1,6 @@ from datetime import datetime +from typing import Dict +import warnings from config import MAX_LEN @@ -20,4 +22,18 @@ def generate_short_title(title): def get_week(d=datetime.today()): - return (int(d.strftime("%W")) + 52 - 5) % 52 \ No newline at end of file + return (int(d.strftime("%W")) + 52 - 5) % 52 + + +def merge_dictionaries(main: Dict, fallback: Dict): + merged = main + for key in fallback.keys(): + if key not in main.keys(): + merged[key] = fallback[key] + elif type(fallback[key]) == dict: + if not type(merged[key]) == dict: + warnings.warn( + f"Main dictionary has invalid format. Replacing entry with key {key} with fallback value.") + merged[key] = fallback[key] + merged[key] = merge_dictionaries(merged[key], fallback[key]) + return merged