Spaces:
Paused
Paused
Delete config_editor.py
Browse files- config_editor.py +0 -72
config_editor.py
DELETED
|
@@ -1,72 +0,0 @@
|
|
| 1 |
-
import json
|
| 2 |
-
import os
|
| 3 |
-
import hashlib
|
| 4 |
-
|
| 5 |
-
if __name__ == "__main__":
|
| 6 |
-
config = None
|
| 7 |
-
path = os.path.dirname(os.path.realpath(__file__))
|
| 8 |
-
os.chdir(path)
|
| 9 |
-
if os.path.exists("config.json"):
|
| 10 |
-
with open("config.json", "r") as f:
|
| 11 |
-
config = json.load(f)
|
| 12 |
-
try:
|
| 13 |
-
config["config"]
|
| 14 |
-
except KeyError:
|
| 15 |
-
config = None
|
| 16 |
-
if config is None:
|
| 17 |
-
print(f"配置文件不存在或为空,创建新配置...")
|
| 18 |
-
config = {"config": []}
|
| 19 |
-
print(f"输入会话ID: ")
|
| 20 |
-
user_data = {"conversation_id": input()}
|
| 21 |
-
print(f"输入cookies: ")
|
| 22 |
-
user_data["cookies"] = input()
|
| 23 |
-
config["config"].append(user_data)
|
| 24 |
-
|
| 25 |
-
again = True
|
| 26 |
-
while True:
|
| 27 |
-
if again:
|
| 28 |
-
num = len(config["config"])
|
| 29 |
-
print(f"\n当前有 {num} 个配置。")
|
| 30 |
-
print("----------")
|
| 31 |
-
print(f"1. 添加新配置")
|
| 32 |
-
print(f"2. 删除所有配置")
|
| 33 |
-
print(f"3. 设置密码")
|
| 34 |
-
print(f"4. 保存并退出")
|
| 35 |
-
choice = input()
|
| 36 |
-
|
| 37 |
-
if choice == "1":
|
| 38 |
-
print(f"输入会话ID: ")
|
| 39 |
-
user_data = {"conversation_id": input()}
|
| 40 |
-
print(f"输入cookies: ")
|
| 41 |
-
user_data["cookies"] = input()
|
| 42 |
-
config["config"].append(user_data)
|
| 43 |
-
print("\n成功添加配置!")
|
| 44 |
-
again = True
|
| 45 |
-
|
| 46 |
-
elif choice == "2":
|
| 47 |
-
print("确定要删除所有配置吗? (y/n)")
|
| 48 |
-
if input().lower() == 'y':
|
| 49 |
-
config["config"] = []
|
| 50 |
-
print("已删除所有配置")
|
| 51 |
-
again = True
|
| 52 |
-
|
| 53 |
-
elif choice == "3":
|
| 54 |
-
print(f"输入新密码(留空则删除密码): ")
|
| 55 |
-
password = input()
|
| 56 |
-
with open("password.txt", "w") as f:
|
| 57 |
-
if password != "":
|
| 58 |
-
f.write(hashlib.sha256(password.encode()).hexdigest())
|
| 59 |
-
print(f"密码已设置")
|
| 60 |
-
else:
|
| 61 |
-
f.write("")
|
| 62 |
-
print(f"密码已删除")
|
| 63 |
-
|
| 64 |
-
elif choice == "4":
|
| 65 |
-
with open("config.json", "w") as f:
|
| 66 |
-
json.dump(config, f, indent=4)
|
| 67 |
-
print("配置已保存")
|
| 68 |
-
break
|
| 69 |
-
|
| 70 |
-
else:
|
| 71 |
-
print(f"无效的选择")
|
| 72 |
-
again = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|