This repository has been archived by the owner on May 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
prtsres.py
350 lines (316 loc) · 12.8 KB
/
prtsres.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
import re, json, time, os
from bs4 import BeautifulSoup
from contextlib import closing
from hoshino.config import RES_DIR
from hoshino import aiorequests
halfdict ={}
icondict ={}
working_path = os.path.abspath(os.path.realpath(os.path.dirname(__file__)))
icon_dir = os.path.join(RES_DIR, "img","akgacha")
half_dir = os.path.join(RES_DIR, "img","akgacha","half")
os.makedirs(icon_dir, exist_ok=True)
os.makedirs(half_dir, exist_ok=True)
char_data = json.load(
open(os.path.join(working_path, "character_table.json"), encoding="utf-8"))
gacha_data = json.load(
open(os.path.join(working_path, "config.json"), encoding="utf-8"))
proxies={ 'http':'socks5h://127.0.0.1:1080',
'https':'socks5h://127.0.0.1:1080'}
async def update_res():
count=0
print("- 更新res资源包...")
chars = json.load(open(os.path.join(working_path, "character_table.json"), encoding="utf-8"))
for k in chars.keys():
name = chars[k]["name"]
if not k.startswith("char"):
pass
r = await aiorequests.get('http://prts.wiki/w/%E5%B9%B2%E5%91%98%E4%B8%80%E8%A7%88')
soup = BeautifulSoup(await r.text)
for index in soup.find(id="mw-content-text").find_all('div'):
try:
if index["class"]==["smwdata"]:
halfdict[index['data-cn']]=index['data-half']
icondict[index['data-cn']]=index['data-icon']
except:
continue
for key in halfdict:
filelink = halfdict[key]
if filelink == None or len(filelink) == 0:
continue
if filelink[0] == "/":
filelink = "https:" + filelink
name=str(key)
id=''
for k in chars.keys():
if name == chars[k]["name"]:
id=str(k)
break
if id == '':
if name == '阿米娅(近卫)':
id="char_1001_amiya2"
pass
else:
print(f'{name}not found!')
continue
filename = f'{id}.png'
png_path = os.path.join(half_dir, filename)
if os.path.exists(png_path):
continue
print(" - 下载", png_path)
png = await (await aiorequests.get(filelink, timeout=20)).content
count+=1
with open(png_path, 'wb') as f:
f.write(png)
for key in icondict:
filelink = icondict[key]
if filelink == None or len(filelink) == 0:
continue
if filelink[0] == "/":
filelink = "https:" + filelink
name=str(key)
id=''
for k in chars.keys():
if name == chars[k]["name"]:
id=str(k)
break
if id == '':
if name == '阿米娅(近卫)':
id="char_1001_amiya2"
pass
else:
print(f'{name}not found!')
continue
filename = f'{id}.png'
png_path = os.path.join(icon_dir, filename)
if os.path.exists(png_path):
continue
png = await (await aiorequests.get(filelink, timeout=20)).content
count+=1
print(" - 下载", png_path)
with open(png_path, 'wb') as f:
f.write(png)
return count
async def update_chara_db():
print("- 更新 character_table...")
global char_data
print("- char_data")
try:
res = await aiorequests.get("https://raw.githubusercontent.com/Kengxxiao/ArknightsGameData/master/zh_CN/gamedata/excel/character_table.json", timeout=20)
except:
res = await aiorequests.get("https://raw.githubusercontent.com/Kengxxiao/ArknightsGameData/master/zh_CN/gamedata/excel/character_table.json", proxies=proxies, timeout=20)
new = await res.json()
if new == char_data:
return 0
char_data = new
with open(os.path.join(working_path, "character_table.json"), "w", encoding="utf-8") as f:
f.write(json.dumps(char_data, indent=2, ensure_ascii=False))
return 1
async def update_config():
global gacha_data
print("- 更新方舟卡池...")
template = {"limited": False, "no_other_6": False, "favor": '',
"open": '', "end": '', "up_6": [], "up_5": [], "up_4": [], "exclude": []}
# get basic info
chars = json.load(
open(os.path.join(working_path, "character_table.json"), encoding="utf-8"))
pool = {
"star_6": [],
"star_5": [],
"star_4": [],
"star_3": [],
"other_chars": [],
"recruit_chars": ["艾丝黛尔", "清流", "火神", "因陀罗"],
"limited_chars": ["W", "年", "迷迭香", "夕","灰烬","霜华","闪击","浊心斯卡蒂","假日威龙陈","耀骑士临光","令","归溟幽灵鲨"]
}
for k in chars.keys():
name = chars[k]["name"]
if not k.startswith("char"):
pass
elif chars[k]["itemObtainApproach"] != "招募寻访" or chars[k]["rarity"] < 2:
pool["other_chars"].append(name)
elif not name in (pool["recruit_chars"] + pool["limited_chars"]):
pool["star_%d" % (chars[k]["rarity"]+1)].append(name)
# get chara onlinetime
print("- online time")
try:
res = await aiorequests.get('http://prts.wiki/w/%E5%B9%B2%E5%91%98%E4%B8%8A%E7%BA%BF%E6%97%B6%E9%97%B4%E4%B8%80%E8%A7%88', timeout=20)
except:
res = await aiorequests.get('http://prts.wiki/w/%E5%B9%B2%E5%91%98%E4%B8%8A%E7%BA%BF%E6%97%B6%E9%97%B4%E4%B8%80%E8%A7%88', proxies=proxies, timeout=30)
text = await res.text
text = text.replace('\n', '')
ret = r'<tr><td>(.*?)<\/td><td>(.*?)<\/td><td>(.*?)<\/td><td>(.*?)<\/td><td>(.*?)<\/td><\/tr>'
result = re.findall(ret, text)
online = {}
for chara in result:
name = re.search('title="(.*?)"', chara[0]).group(1)
onlinetime = time.mktime(time.strptime(chara[2], "%Y年%m月%d日 %H:%M"))
online[name] = onlinetime
# get limited gacha
print("- 限定卡池")
try:
res = await aiorequests.get('http://prts.wiki/w/%E5%8D%A1%E6%B1%A0%E4%B8%80%E8%A7%88/%E9%99%90%E6%97%B6%E5%AF%BB%E8%AE%BF', timeout=20)
except:
res = await aiorequests.get('http://prts.wiki/w/%E5%8D%A1%E6%B1%A0%E4%B8%80%E8%A7%88/%E9%99%90%E6%97%B6%E5%AF%BB%E8%AE%BF', proxies=proxies, timeout=20)
text = await res.text
text = text.replace('\n', '')
# 去除嵌套表格
text = re.sub(r'<table class="wikitable mw-collapsible mw-collapsed">(.*?)</table>', '', text)
banner = {}
limited = re.findall("<table(.*?)</table>", text)
ret = r'<tr><td>(.*?)<\/td><td>(.*?)<\/td><td>(.*?)<\/td><td>(.*?)<\/td><\/tr>'
result = re.findall(ret, limited[0] )
print(len(result))
for gacha in result:
name = re.search('title="(.*?)"', gacha[0]).group(1)
name = name.replace('寻访模拟/', '')
gachatime = re.search(
'(\d{4}-\d{2}-\d{2} \d{2}:\d{2}).*?(\d{4}-\d{2}-\d{2} \d{2}:\d{2})', gacha[1])
if not gachatime:
print(f"gacha{name}time format error!")
continue
opentime = gachatime.group(1)
opentimestp = time.mktime(time.strptime(opentime, "%Y-%m-%d %H:%M"))
endtime = gachatime.group(2)
endtimestp = time.mktime(time.strptime(endtime, "%Y-%m-%d %H:%M"))
exclude = []
for star in [pool["star_6"], pool["star_5"], pool["star_4"], pool["star_3"]]:
for chara in star:
if chara not in online:
exclude.append(chara)
continue
elif online[chara] > opentimestp:
exclude.append(chara)
star6 = re.findall('title="(.*?)"', gacha[2])
if len(star6) == 0:
print(f"gacha{name} star6 count error!")
continue
star5 = re.findall('title="(.*?)"', gacha[3])
star4 = []
starex = re.findall(
'%E7%A8%80%E6%9C%89%E5%BA%A6_%E9%BB%84_(\d).png', gacha[3])
for i in range(0, len(starex)):
if starex[i] == '3':
star4.append(star5[i])
for item in star4:
if item in star5:
star5.remove(item)
cur = template.copy()
cur["limited"] = True
cur["favor"] = star6[0]
cur["open"] = opentimestp
cur["end"] = endtimestp
cur["up_6"] = star6
cur["up_5"] = star5
cur["up_4"] = star4
print(name, cur["favor"])
cur["exclude"] = exclude
banner[name] = cur
# get timelimit gacha
print("- 限时卡池")
result = re.findall(ret, limited[1])
for gacha in result:
name = re.search('title="(.*?)"', gacha[0]).group(1)
name = name.replace('寻访模拟/', '')
gachatime = re.search(
'(\d{4}-\d{2}-\d{2} \d{2}:\d{2}).*?(\d{4}-\d{2}-\d{2} \d{2}:\d{2})', gacha[1])
if not gachatime:
print(f"gacha{name}time format error!")
continue
opentime = gachatime.group(1)
opentimestp = time.mktime(time.strptime(opentime, "%Y-%m-%d %H:%M"))
endtime = gachatime.group(2)
endtimestp = time.mktime(time.strptime(endtime, "%Y-%m-%d %H:%M"))
exclude = []
for star in [pool["star_6"], pool["star_5"], pool["star_4"], pool["star_3"]]:
for chara in star:
if chara not in online:
exclude.append(chara)
continue
elif online[chara] > opentimestp:
exclude.append(chara)
star6 = re.findall('title="(.*?)"', gacha[2])
star5 = re.findall('title="(.*?)"', gacha[3])
star4 = []
starex = re.findall(
'%E7%A8%80%E6%9C%89%E5%BA%A6_%E9%BB%84_(\d).png', gacha[3])
for i in range(0, len(starex)):
if starex[i] == '3':
star4.append(star5[i])
for item in star4:
if item in star5:
star5.remove(item)
cur = template.copy()
cur["limited"] = False
cur["no_other_6"] = True if "联合行动" in name else False
cur["favor"] = star6[0] if len(star6) > 1 else ''
cur["open"] = opentimestp
cur["end"] = endtimestp
cur["up_6"] = star6
cur["up_5"] = star5
cur["up_4"] = star4
print(name, star6)
cur["exclude"] = exclude
banner[name] = cur
# get normal gacha
print("- 普池")
textn=""
for year in ["2022","2021","2020","2019"]:
url=f"http://prts.wiki/api.php?action=parse&format=json&page=%E5%8D%A1%E6%B1%A0%E4%B8%80%E8%A7%88%2F%E5%B8%B8%E9%A9%BB%E6%A0%87%E5%87%86%E5%AF%BB%E8%AE%BF%2F{year}"
try:
res2 = await aiorequests.get(url, timeout=20)
except:
res2 = await aiorequests.get(url, timeout=20)
resj= await res2.json()
text2=resj["parse"]["text"]["*"].replace('\n', '').replace('\\', '')
text=text+text2
ret2 = r'<tr><td>(\d*?)<\/td><td>(.*?)<\/td><td>(.*?)<\/td><td>(.*?)<\/td><td>(.*?)<\/td><\/tr>'
result2 = re.findall(ret2, text)
for gacha in result2:
gachaid = gacha[0]
gachatime = re.search(
'(\d{4}-\d{2}-\d{2} \d{2}:\d{2}).*?(\d{4}-\d{2}-\d{2} \d{2}:\d{2})', gacha[2])
if not gachatime:
print(f"id{gachaid}time format error!")
continue
opentime = gachatime.group(1)
opentimestp = time.mktime(time.strptime(opentime, "%Y-%m-%d %H:%M"))
endtime = gachatime.group(2)
endtimestp = time.mktime(time.strptime(endtime, "%Y-%m-%d %H:%M"))
exclude = []
for star in [pool["star_6"], pool["star_5"], pool["star_4"], pool["star_3"]]:
for chara in star:
if chara not in online:
exclude.append(chara)
continue
elif online[chara] > opentimestp:
exclude.append(chara)
star6 = re.findall('title="(.*?)"', gacha[3])
star5 = re.findall('title="(.*?)"', gacha[4])
star4 = []
starex = re.findall(
'%E7%A8%80%E6%9C%89%E5%BA%A6_%E9%BB%84_(\d).png', gacha[4])
for i in range(0, len(starex)):
if starex[i] == '3':
star4.append(star5[i])
for item in star4:
if item in star5:
star5.remove(item)
cur = template.copy()
cur["id"] = gachaid
cur["favor"] = star6[-1] if len(star6) > 1 else ''
cur["open"] = opentimestp
cur["end"] = endtimestp
cur["id"] = gachaid
cur["up_6"] = star6
cur["up_5"] = star5
cur["up_4"] = star4
print(gachaid, star6)
cur["exclude"] = exclude
banner[f'普池#{gachaid}'] = cur
new = {"banners": banner, "pool": pool}
if new == gacha_data:
return 0
gacha_data = new
with open(os.path.join(working_path, "config.json"), "w", encoding="utf-8") as f:
f.write(json.dumps(gacha_data, indent=2, ensure_ascii=False))
return 1