56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
"""
|
|
更新用户Cookie Cloud参数
|
|
"""
|
|
import json
|
|
import sqlite3
|
|
import os
|
|
|
|
DB_PATH = os.path.join(os.path.dirname(__file__), 'backend', 'instance', 'cookie_monitor.db')
|
|
|
|
def update_user_cookie_cloud():
|
|
"""更新用户Cookie Cloud参数"""
|
|
with open('config.json', 'r', encoding='utf-8') as f:
|
|
config = json.load(f)
|
|
|
|
conn = sqlite3.connect(DB_PATH)
|
|
cursor = conn.cursor()
|
|
|
|
# 添加新列(如果不存在)
|
|
columns_to_add = [
|
|
('cookie_cloud_uuid', 'VARCHAR(255)'),
|
|
('cookie_cloud_password', 'VARCHAR(255)'),
|
|
('cookie_cloud_api_url', 'VARCHAR(255)')
|
|
]
|
|
|
|
for col_name, col_type in columns_to_add:
|
|
try:
|
|
cursor.execute(f"ALTER TABLE users ADD COLUMN {col_name} {col_type}")
|
|
print(f"添加列: {col_name}")
|
|
except sqlite3.OperationalError as e:
|
|
if 'duplicate column name' in str(e).lower():
|
|
print(f"列已存在: {col_name}")
|
|
else:
|
|
raise
|
|
|
|
for user_config in config['users']:
|
|
user_name = user_config['name']
|
|
cc = user_config.get('cookie_cloud', {})
|
|
|
|
cursor.execute(
|
|
"UPDATE users SET cookie_cloud_uuid = ?, cookie_cloud_password = ?, cookie_cloud_api_url = ? WHERE name = ?",
|
|
(
|
|
cc.get('uuid', ''),
|
|
cc.get('password', ''),
|
|
cc.get('api_url', ''),
|
|
user_name
|
|
)
|
|
)
|
|
print(f"更新用户 {user_name}: UUID={cc.get('uuid', '')}, API={cc.get('api_url', '')}")
|
|
|
|
conn.commit()
|
|
conn.close()
|
|
print("\n更新完成!")
|
|
|
|
if __name__ == '__main__':
|
|
update_user_cookie_cloud()
|