diff options
| author | yum <yum.food.vr@gmail.com> | 2025-05-17 23:41:20 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-05-17 23:54:56 -0700 |
| commit | f8e95c0b85288a10f435e0edabf43defa0c303ac (patch) | |
| tree | c0fd2d499cd7ee6e51947f1df62e7cad05b67816 /app_config.py | |
| parent | 0c54e1fc74fe7677a0d4fef1c147c6e886d182db (diff) | |
Add STT code
Diffstat (limited to 'app_config.py')
| -rw-r--r-- | app_config.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/app_config.py b/app_config.py new file mode 100644 index 0000000..f911456 --- /dev/null +++ b/app_config.py @@ -0,0 +1,39 @@ +import os +import sys +import typing + +def getConfig(path: str) -> typing.Dict[str, typing.Union[str, float, int, bool]]: + # Helper functions to detect and convert the type + def is_int(value: str) -> bool: + try: + int(value) + return True + except ValueError: + return False + + def is_float(value: str) -> bool: + try: + float(value) + return True + except ValueError: + return False + + def convert_value(key: str, value: str): + if key.startswith(("enable_", "remove_", "use_", "clear_")): + return bool(int(value)) + elif is_int(value): + return int(value) + elif is_float(value): + return float(value) + else: + return value + + config = {} + with open(path, 'r') as file: + for line in file: + key_value = line.strip().split(": ", maxsplit=1) + key = key_value[0] + value = key_value[1] if len(key_value) > 1 else "" + config[key] = convert_value(key, value.strip()) + return config + |
