sp-hydra-veil-gui/SMS-Exchange-Linux-GUI/local_data_operations/load_or_setup_config.py
2026-01-28 13:13:57 +01:00

54 lines
1.9 KiB
Python
Executable file

from local_data_operations.search_or_setup_json import get_the_path_of_the_folder_for, load_json_as_dict, replace_and_save_value_in_json
import json
import os
def get_default_config():
default_json_content = {
"error_log_file_path": "error_log_for_gui.txt",
"local_data": True,
"default_currency": False,
"turn_off_email_option": False,
"turn_off_proxy_option": False,
"cache_available": True,
}
return default_json_content
def load_or_setup_local_api_data_folder():
path_for_data = get_the_path_of_the_folder_for('.local/share', 'api_data')
# Check if the folder exists
if not os.path.exists(path_for_data):
# Create the folder if it doesn't exist
os.makedirs(path_for_data)
print(f"Folder '{path_for_data}' created.")
else:
print(f"Folder '{path_for_data}' already exists.")
return path_for_data
def load_or_setup_config(json_file_name):
# setup configs file:
path_for_configs = get_the_path_of_the_folder_for('.config', 'sms')
default_json_content = get_default_config()
raw_data = load_json_as_dict(path_for_configs, json_file_name, default_json_content)
# Return data in searchable format:
return raw_data
# for the initial jsons from the API:
def setup_path_to_dump_initial_api_data(filename):
path_for_configs = get_the_path_of_the_folder_for('.config', 'api_data')
final_file_path = f"{path_for_configs}/{filename}"
return final_file_path
def replace_config_value(json_file_name, key_value_to_find, value_to_replace):
# setup configs file:
path_for_configs = get_the_path_of_the_folder_for('.config', 'sms')
default_json_content = get_default_config()
new_data_set = replace_and_save_value_in_json(path_for_configs, json_file_name, default_json_content, key_value_to_find, value_to_replace)
return new_data_set