Delete uploader.py
Browse files- uploader.py +0 -53
uploader.py
DELETED
|
@@ -1,53 +0,0 @@
|
|
| 1 |
-
import json
|
| 2 |
-
import requests
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
from logger import log
|
| 5 |
-
|
| 6 |
-
class AccountUploader:
|
| 7 |
-
def __init__(self, api_host, admin_key):
|
| 8 |
-
self.api_host = api_host.rstrip("/")
|
| 9 |
-
self.admin_key = admin_key
|
| 10 |
-
self.session = requests.Session()
|
| 11 |
-
|
| 12 |
-
def login(self):
|
| 13 |
-
log("连接服务器中...")
|
| 14 |
-
r = self.session.post(
|
| 15 |
-
f"{self.api_host}/login",
|
| 16 |
-
data={"admin_key": self.admin_key},
|
| 17 |
-
timeout=30
|
| 18 |
-
)
|
| 19 |
-
if self.session.cookies:
|
| 20 |
-
log("服务器登录成功", "OK")
|
| 21 |
-
return True
|
| 22 |
-
log("服务器登录失败", "ERROR")
|
| 23 |
-
return False
|
| 24 |
-
|
| 25 |
-
def upload_and_merge(self, file_path):
|
| 26 |
-
if not Path(file_path).exists():
|
| 27 |
-
log("账号文件不存在", "ERROR")
|
| 28 |
-
return False
|
| 29 |
-
|
| 30 |
-
local = json.load(open(file_path, "r", encoding="utf-8"))
|
| 31 |
-
|
| 32 |
-
r = self.session.get(f"{self.api_host}/admin/accounts-config", timeout=30)
|
| 33 |
-
remote = r.json().get("accounts", []) if r.status_code == 200 else []
|
| 34 |
-
|
| 35 |
-
ids = {a["id"] for a in remote}
|
| 36 |
-
merged = remote[:]
|
| 37 |
-
|
| 38 |
-
for a in local:
|
| 39 |
-
if a["id"] not in ids:
|
| 40 |
-
merged.append(a)
|
| 41 |
-
|
| 42 |
-
r = self.session.put(
|
| 43 |
-
f"{self.api_host}/admin/accounts-config",
|
| 44 |
-
json=merged,
|
| 45 |
-
timeout=30
|
| 46 |
-
)
|
| 47 |
-
|
| 48 |
-
if r.status_code == 200:
|
| 49 |
-
log(f"上传完成,共 {len(merged)} 个账号", "OK")
|
| 50 |
-
return True
|
| 51 |
-
|
| 52 |
-
log("上传失败", "ERROR")
|
| 53 |
-
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|