35 lines
947 B
Python
35 lines
947 B
Python
import json
|
|
import os
|
|
import time
|
|
|
|
CONFIG_FILE = os.path.join(os.path.dirname(__file__), "config.json")
|
|
|
|
USERNAME = "your_username" # 替换为你的学习通用户名
|
|
PASSWORD = "your_password" # 替换为你的学习通密码
|
|
QR_LOGIN = False # 设为 True 启用二维码登录(优先级高于账号密码)
|
|
|
|
|
|
def save_cookies(cookies_dict: dict):
|
|
data = {
|
|
"cookies": cookies_dict,
|
|
"saved_at": int(time.time()),
|
|
}
|
|
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
|
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
|
|
|
|
|
def load_cookies() -> dict | None:
|
|
if not os.path.exists(CONFIG_FILE):
|
|
return None
|
|
try:
|
|
with open(CONFIG_FILE, "r", encoding="utf-8") as f:
|
|
data = json.load(f)
|
|
return data.get("cookies")
|
|
except (json.JSONDecodeError, IOError):
|
|
return None
|
|
|
|
|
|
def clear_cookies():
|
|
if os.path.exists(CONFIG_FILE):
|
|
os.remove(CONFIG_FILE)
|