forked from Womsxd/MihoyoBBSTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account.py
33 lines (26 loc) · 1.15 KB
/
account.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import login
import config
import setting
from error import CookieError
from request import http
from loghelper import log
def get_account_list(game_id: str, headers: dict, update: bool = False) -> list:
game_name = setting.game_id2name.get(game_id, game_id)
if update and login.update_cookie_token():
headers['Cookie'] = config.config['account']['cookie']
elif update:
log.warning(f"获取{game_name}账号列表失败!")
raise CookieError("BBS Cookie Error")
log.info(f"正在获取米哈游账号绑定的{game_name}账号列表...")
response = http.get(setting.account_Info_url, params={"game_biz": game_id}, headers=headers)
data = response.json()
if data["retcode"] == -100:
return get_account_list(game_id, headers, update=True)
if data["retcode"] != 0:
log.warning(f"获取{game_name}账号列表失败!")
return []
account_list = []
for i in data["data"]["list"]:
account_list.append([i["nickname"], i["game_uid"], i["region"]])
log.info(f"已获取到{len(account_list)}个{setting.game_id2name.get(game_id, game_id)}账号信息")
return account_list