#!/usr/bin/python
import importlib.resources as pkg
import json

def main():
    with pkg.path("orchestraw", "config.json") as config_path:
        with open(config_path, "r+") as config:
            content = config.read()
            setting = json.loads(content)
            print("当前请求接口配置为:" + setting["api"])
            opt = input('您要修改此配置吗?[y/N]')
            if opt.lower() == "y":
                try:
                    newopt = input("请输入新的配置:")
                    setting["api"] = newopt
                    config.seek(0)  # 将文件指针移回文件开头
                    config.write(json.dumps(setting))
                    config.truncate()  # 截断文件，确保内容正确
                except Exception as e:
                    print("出现错误:" + str(e))

if __name__ == "__main__":
    main()