import sys import json #should pass the path of the .env file as the first argument #should pass the path of the secrets .env file as the second argument # python3 turn_app_setting_json_to_dotenv.py config.env secrets.env def load_env_file(dotenv_path, override=False): with open(dotenv_path) as file_obj: lines = file_obj.read().splitlines() # Removes \n from lines dotenv_vars = {} for line in lines: line = line.strip() if not line or line.startswith("#") or "=" not in line: continue key, value = line.split("=", maxsplit=1) dotenv_vars.setdefault(key, value) return dotenv_vars config_path = sys.argv[1] secret_path = sys.argv[2] config = load_env_file(config_path) secret = load_env_file(secret_path) print(len(config)) print(len(secret)) all_envs = config.copy() all_envs.update(secret) print(len(all_envs)) setting_list = [] for k, v in all_envs.items(): setting = {} setting["name"] = k setting["value"] = v setting["slotSetting"] = "false" setting_list.append(setting) app_settings_file = open("appsettings.json", "w") app_settings_file.write(json.dumps(setting_list))