-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhmx-card-analysis.py
178 lines (157 loc) · 6.29 KB
/
whmx-card-analysis.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
from requests import post
import qrcode
import time
from colorama import init,Fore,Back,Style
from colorama import init,Fore,Back,Style
init(autoreset=True)
class Colored(object):
'''
设置控制台字体颜色
'''
# 前景色:红色 背景色:默认
def red(self, s):
return Fore.RED + s + Fore.RESET
# 前景色:绿色 背景色:默认
def green(self, s):
return Fore.GREEN + s + Fore.RESET
# 前景色:黄色 背景色:默认
def yellow(self, s):
return Fore.YELLOW + s + Fore.RESET
# 前景色:蓝色 背景色:默认
def blue(self, s):
return Fore.BLUE + s + Fore.RESET
color = Colored()
class get_userinfo():
'''
获取用户用于登录的access_key和uid
'''
def __init__(self,):
'''
初始化
'''
self.url = "https://goda.srap.link/qrcode_login"
self.check_url = "https://goda.srap.link/check_qrcode"
self.card_info_url = "https://goda.srap.link/getDrawCardHistory"
self.headers = {
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
'Accept': '*/*',
'Host': 'goda.srap.link',
'Connection': 'keep-alive',
}
def get_qrcode(self):
'''
获取二维码,返回ticket
'''
data = post(self.url, headers=self.headers)
if data.json()['status'] != True:
print("获取用户信息失败")
data = data.json()
qrcode_data = data.get('data')
user_info_url = "biligame://portal/auth/login/qrcode?" + qrcode_data
img = qrcode.make(user_info_url)
img.show()
self.qrcode_data = qrcode_data
return qrcode_data
def check_qrcode(self,qrcode_data):
payload = {
"ticket": str(qrcode_data)
}
response_qrcode = None
while not response_qrcode or response_qrcode.json()['status']==False:
response_qrcode = post(self.check_url, headers=self.headers,json=payload)
time.sleep(1)
self.account_info = response_qrcode.json()['data']
def get_account_info(self):
access_key = self.account_info.get('access_key')
uid = self.account_info.get('uid')
return access_key, uid
def get_card_info(self,access_key,uid):
pages = 1
card_info = None
card_info_list = []
while card_info == None or card_info.json().get('message')!="发生错误":
payload = {
"code": str(access_key),
"uid": str(uid),
"page": pages,
"pagesize": 10,
"type": [
"time"
],
}
card_info = post(self.card_info_url, headers=self.headers,json=payload)
if card_info.json().get('data') != []:
card_info_list.append(card_info.json().get('data'))
print(f"获取到第{pages}页数据")
pages += 1
return card_info_list
class card_analysis():
'''
分析卡池信息
继承自get_userinfo类
'''
def analysis_card_info(self,card_info_list):
techu, youyi, xinsheng = 0,0,0
CardName_list = []
for card_info in card_info_list:
for i in card_info:
card_name = i.get('CardName')
rare = i.get('Rare')
if rare == 4:
CardName_list.append(card_name)
techu += 1
elif rare == 3:
youyi += 1
elif rare == 2:
xinsheng += 1
print(color.green("抽卡总数:{}".format(techu+youyi+xinsheng)))
print(color.green("出红概率:{:.2f}%".format(float(techu/(techu+youyi+xinsheng))*100)))
print(color.red(f"特出器者:{techu}"),end=" ")
for i in CardName_list:
print(color.red(f"{i}"),end=" ")
print(color.yellow(f"\n优异器者:{youyi}"))
print(color.blue(f"新生器者:{xinsheng}"))
def all_card_info(self,card_info_list):
'''
打印所有卡池信息
'''
all_card_info = []
for card_info in card_info_list:
for i in card_info:
pool_name = i.get('PoolName')
card_name = i.get('CardName')
rare = i.get('Rare')
all_card_info.append(f"卡池:{pool_name},器者:{card_name},稀有度:{rare}")
return all_card_info
if __name__ == '__main__':
user_info = get_userinfo()
qrcode_data = user_info.get_qrcode()
user_info.check_qrcode(qrcode_data=qrcode_data)
access_key, uid = user_info.get_account_info()
card_info_list = user_info.get_card_info(access_key,uid)
card_analysis = card_analysis()
card_analysis.analysis_card_info(card_info_list)
user_input = None
while user_input ==None or user_input not in ['e']:
user_input = input("输入y查看所有卡池信息,输入s保存卡池信息到目录下card_info.txt文件,输入e退出:")
if user_input == 'y':
print(f"卡池信息如下:",end='\n')
for card_info in card_info_list:
for i in card_info:
pool_name = i.get('PoolName')
card_name = i.get('CardName')
rare = i.get('Rare')
if rare == 4:
print(color.red(f"卡池:{pool_name},器者:{card_name},稀有度:{rare}"))
elif rare == 3:
print(color.yellow(f"卡池:{pool_name},器者:{card_name},稀有度:{rare}"))
elif rare == 2:
print(color.blue(f"卡池:{pool_name},器者:{card_name},稀有度:{rare}"))
elif user_input =='s':
with open('card_info.txt','w',encoding='utf-8') as f:
f.write("查询时间:{}\n".format(time.strftime('%Y-%m-%d %H:%M:%S')))
card_data = card_analysis.all_card_info(card_info_list)
for card_info in card_data:
f.write(str(card_info))
f.write('\n')
print("卡池信息保存成功")