forked from benx1n/wows-stats-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source.py
357 lines (330 loc) · 10.6 KB
/
data_source.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
from dataclasses import dataclass
from typing import Tuple,List
import time
import traceback
from pathlib import Path
from bs4 import BeautifulSoup
import re
dir_path = Path(__file__).parent
template_path = dir_path / "template"
@dataclass
class matching:
keywords: Tuple[str, ...]
match_keywords : str
nations = [
matching(("commonwealth","英联邦",),"commonwealth"),
matching(("europe","欧洲",),"europe"),
matching(("france","法国",),"france"),
matching(("germany","德国",),"germany"),
matching(("italy","意大利",),"italy"),
matching(("japan","日本",),"japan"),
matching(("pan_america","泛美",),"pan_america"),
matching(("pan_asia","泛亚",),"pan_asia"),
matching(("uk","英国","United_Kingdom"),"United_Kingdom"),
matching(("usa","美国",),"usa"),
matching(("ussr","苏联",),"Russia"),
matching(("netherlands","荷兰",),"netherlands"),
matching(("spain","西班牙",),"spain"),
]
shiptypes = [
matching(("Cruiser","巡洋舰","巡洋","CA"),"Cruiser"),
matching(("Battleship","战列舰","战列","BB"),"Battleship"),
matching(("Destroyer","驱逐舰","驱逐","DD"),"Destroyer"),
matching(("Submarine","潜艇","SS"),"Submarine"),
matching(("Auxiliary","辅助舰艇","DD"),"Auxiliary"),
matching(("AirCarrier","航空母舰","航母","CV"),"AirCarrier"),
]
levels = [
matching(("1","1级","一级","一"),"1"),
matching(("2","2级","二级","二"),"2"),
matching(("3","3级","三级","三"),"3"),
matching(("4","4级","四级","四"),"4"),
matching(("4","4级","四级","四"),"4"),
matching(("5","5级","五级","五"),"5"),
matching(("6","6级","六级","六"),"6"),
matching(("7","7级","七级","七"),"7"),
matching(("8","8级","八级","八"),"8"),
matching(("9","9级","九级","九"),"9"),
matching(("10","10级","十级","十"),"10"),
matching(("11","11级","十一级","十一"),"11"),
]
servers = [
matching(("asia","亚服","asian"),"asia"),
matching(("eu","欧服","europe"),"eu"),
matching(("na","美服","NorthAmerican"),"na"),
matching(("ru","俄服","Russia"),"ru"),
matching(("cn","国服","china"),"cn"),
]
tiers = ["Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ", "Ⅶ", "Ⅷ", "Ⅸ", "Ⅹ", "Ⅺ"]
number_url_homes={
"asia":"https://asia.wows-numbers.com",
"eu":"https://wows-numbers.com",
"na":"https://na.wows-numbers.com",
"ru":"https://ru.wows-numbers.com",
"cn": None
}
pr_select = [
{
"value": 0,
"name": "还需努力",
"englishName": "Bad",
"color": "#FE0E00"
},
{
"value": 750,
"name": "低于平均",
"englishName": "Below Average",
"color": "#FE7903"
},
{
"value": 1100,
"name": "平均水平",
"englishName": "Average",
"color": "#FFC71F"
},
{
"value": 1350,
"name": "好",
"englishName": "Good",
"color": "#44B300"
},
{
"value": 1550,
"name": "很好",
"englishName": "Very Good",
"color": "#318000"
},
{
"value": 1750,
"name": "非常好",
"englishName": "Great",
"color": "#02C9B3"
},
{
"value": 2100,
"name": "大佬水平",
"englishName": "Unicum",
"color": "#D042F3"
},
{
"value": 2450,
"name": "神佬水平",
"englishName": "Super Unicum",
"color": "#A00DC5"
}
]
color_data = {
"Bad": "#FE0E00",
"Below Average": "#FE7903",
"Average": "#FFC71F",
"Good": "#44B300",
"Very Good": "#318000",
"Great": "#02C9B3",
"Unicum": "#D042F3",
"Super Unicum": "#A00DC5"
}
async def set_infoparams(List):
try:
result = {
"template_path":template_path,
"data":List
}
return result
except Exception:
traceback.print_exc()
async def set_recentparams(List):
try:
result = {
"data":List
}
return result
except Exception:
traceback.print_exc()
async def set_shipparams(List):
try:
result = {
"data":List,
}
return result
except Exception:
traceback.print_exc()
async def set_shipRecentparams(List):
try:
result = {
"data":List,
}
return result
except Exception:
traceback.print_exc()
async def select_prvalue_and_color(pr:int):
for select in pr_select :
if pr > select['value']:
describe = select['name']
color = select['color']
return describe,color
async def set_ShipRank_Numbers(data,server,shipId):
try:
info_list = list()
for each in data[0:10]:
index = int(each.select('td')[0].string)
clan_name = each.select('td[style="text-align: left; "] a')
if len(clan_name) > 1:
tag = clan_name[0].string.replace("[",'').replace("]",'')
userName = clan_name[1].string
url = clan_name[1].attrs['href']
else:
tag = None
userName = clan_name[0].string
url = clan_name[0].attrs['href']
accountId = await search_accountId(url)
battles = int(each.select('td span')[0].string.replace(' ',''))
pr = int(each.select('td span')[1].string.replace(' ',''))
prColor = await search_color(each.select('td span')[1].attrs['style'])
wins = float(each.select('td span')[2].string.replace('%',''))
winsColor = await search_color(each.select('td span')[2].attrs['style'])
frags = float(each.select('td span')[3].string)
fragsColor = await search_color(each.select('td span')[3].attrs['style'])
maxFrags = int(each.select('td span')[4].string)
damage = int(each.select('td span')[5].string.replace(' ',''))
damageColor = await search_color(each.select('td span')[5].attrs['style'])
maxDamage = int(each.select('td span')[6].string.replace(' ',''))
xp = int(each.select('td span')[7].string.replace(' ',''))
maxXp = int(each.select('td span')[8].string.replace(' ',''))
planesDestroyed = float(each.select('td span')[9].string)
planesDestroyedColor = await search_color(each.select('td span')[9].attrs['style'])
maxPlanesDestroyed = int(each.select('td span')[10].string)
info ={
"accountId":accountId,
"battles":battles,
"damage":damage,
"damageColor":damageColor,
"frags":frags,
"fragsColor":fragsColor,
"index":index,
"maxDamage":maxDamage,
"maxFrags":maxFrags,
"maxPlanesDestroyed":maxPlanesDestroyed,
"maxXp":maxXp,
"planesDestroyed":planesDestroyed,
"planesDestroyedColor":planesDestroyedColor,
"pr":pr,
"prColor":prColor,
"server":server,
"shipId":shipId,
"wins":wins,
"winsColor":winsColor,
"xp":xp,
"tag":tag,
"userName":userName
}
info_list.append(info)
return info_list
except Exception:
traceback.print_exc()
return None
async def set_clanparams():
result = {
"template_path":template_path,
}
return result
async def set_clanRecord_params():
return
async def search_accountId(str):
try:
match = re.search(r"/player/(.*?),",str)
if match:
return int(match.group(1).strip())
else:
return None
except Exception:
traceback.print_exc()
return None
async def search_color(str):
try:
match = re.search(r"color:(.*?);",str)
if match:
return match.group(1).strip()
else:
return None
except Exception:
traceback.print_exc()
return None
async def set_damageColor(type,value):
try:
if type == 'Destroyer':
if not value or value < 33000:
return color_data["Bad"]
elif value < 40000:
return color_data["Good"]
elif value < 55000:
return color_data["Great"]
elif value < 64000:
return color_data["Unicum"]
else:
return color_data["Super Unicum"]
elif type == 'Cruiser':
if not value or value < 47000:
return color_data["Bad"]
elif value < 55000:
return color_data["Good"]
elif value < 83000:
return color_data["Great"]
elif value < 95000:
return color_data["Unicum"]
else:
return color_data["Super Unicum"]
elif type == 'AirCarrier':
if not value or value < 60000:
return color_data["Bad"]
elif value < 71000:
return color_data["Good"]
elif value < 84000:
return color_data["Great"]
elif value < 113000:
return color_data["Unicum"]
else:
return color_data["Super Unicum"]
else:
if not value or value < 64000:
return color_data["Bad"]
elif value < 72000:
return color_data["Good"]
elif value < 97000:
return color_data["Great"]
elif value < 108000:
return color_data["Unicum"]
else:
return color_data["Super Unicum"]
except Exception:
traceback.print_exc()
return None
async def set_winColor(value):
try:
if not value or value < 45:
return color_data["Bad"]
elif value < 50:
return color_data["Below Average"]
elif value < 55:
return color_data["Average"]
elif value < 60:
return color_data["Good"]
elif value < 65:
return color_data["Great"]
elif value < 70:
return color_data["Unicum"]
else:
return color_data["Super Unicum"]
except Exception:
traceback.print_exc()
return None
async def set_upinfo_color(value):
try:
if not value or value < 0 :
return color_data["Bad"]
elif value > 0 :
return color_data["Good"]
else:
return None
except Exception:
traceback.print_exc()
return None