update
BIN
assets/chemicalcode/special_id/140526.png
Normal file
After Width: | Height: | Size: 548 B |
BIN
assets/chemicalcode/special_id/20473555.png
Normal file
After Width: | Height: | Size: 425 B |
BIN
assets/chemicalcode/special_id/21865276.png
Normal file
After Width: | Height: | Size: 673 B |
BIN
assets/chemicalcode/special_id/21865280.png
Normal file
After Width: | Height: | Size: 736 B |
BIN
assets/chemicalcode/special_id/22398.png
Normal file
After Width: | Height: | Size: 174 B |
BIN
assets/chemicalcode/special_id/4509317.png
Normal file
After Width: | Height: | Size: 576 B |
BIN
assets/chemicalcode/special_id/4509318.png
Normal file
After Width: | Height: | Size: 670 B |
BIN
assets/chemicalcode/special_id/4510681.png
Normal file
After Width: | Height: | Size: 764 B |
BIN
assets/chemicalcode/special_id/4510778.png
Normal file
After Width: | Height: | Size: 752 B |
BIN
assets/chemicalcode/special_id/4512975.png
Normal file
After Width: | Height: | Size: 654 B |
BIN
assets/chemicalcode/special_id/4514248.png
Normal file
After Width: | Height: | Size: 574 B |
BIN
assets/chemicalcode/special_id/4514266.png
Normal file
After Width: | Height: | Size: 453 B |
BIN
assets/chemicalcode/special_id/4514293.png
Normal file
After Width: | Height: | Size: 174 B |
BIN
assets/chemicalcode/special_id/4514330.png
Normal file
After Width: | Height: | Size: 746 B |
BIN
assets/chemicalcode/special_id/4514408.png
Normal file
After Width: | Height: | Size: 341 B |
BIN
assets/chemicalcode/special_id/4514534.png
Normal file
After Width: | Height: | Size: 650 B |
BIN
assets/chemicalcode/special_id/4514586.png
Normal file
After Width: | Height: | Size: 513 B |
BIN
assets/chemicalcode/special_id/4514603.png
Normal file
After Width: | Height: | Size: 778 B |
BIN
assets/chemicalcode/special_id/4515054.png
Normal file
After Width: | Height: | Size: 570 B |
BIN
assets/chemicalcode/special_id/4573995.png
Normal file
After Width: | Height: | Size: 619 B |
BIN
assets/chemicalcode/special_id/4574465.png
Normal file
After Width: | Height: | Size: 594 B |
BIN
assets/chemicalcode/special_id/4575369.png
Normal file
After Width: | Height: | Size: 381 B |
BIN
assets/chemicalcode/special_id/4575370.png
Normal file
After Width: | Height: | Size: 546 B |
BIN
assets/chemicalcode/special_id/4575371.png
Normal file
After Width: | Height: | Size: 448 B |
BIN
assets/chemicalcode/special_id/4885606.png
Normal file
After Width: | Height: | Size: 736 B |
BIN
assets/chemicalcode/special_id/4885717.png
Normal file
After Width: | Height: | Size: 491 B |
BIN
assets/chemicalcode/special_id/4886482.png
Normal file
After Width: | Height: | Size: 568 B |
BIN
assets/chemicalcode/special_id/4886484.png
Normal file
After Width: | Height: | Size: 331 B |
|
@ -1,4 +1,5 @@
|
|||
import asyncio
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import traceback
|
||||
|
@ -26,11 +27,11 @@ special_id = ["22398", "140526", "4509317", "4509318", "4510681", "4510778", "45
|
|||
@retry(stop=stop_after_attempt(3), reraise=True)
|
||||
async def search_csr(id=None): # 根据 ChemSpider 的 ID 查询 ChemSpider 的链接,留空(将会使用缺省值 None)则随机查询
|
||||
if id is not None: # 如果传入了 ID,则使用 ID 查询
|
||||
answer = id
|
||||
answer_id = id
|
||||
else:
|
||||
answer = random.randint(1, 12198914) # 否则随机查询一个题目
|
||||
answer = str(answer)
|
||||
get = await get_url(csr_link + '/Search.aspx?q=' + answer, 200, fmt='text') # 在 ChemSpider 上搜索此化学式或 ID
|
||||
answer_id = random.randint(1, 12198914) # 否则随机查询一个题目
|
||||
answer_id = str(answer_id)
|
||||
get = await get_url(csr_link + '/Search.aspx?q=' + answer_id, 200, fmt='text') # 在 ChemSpider 上搜索此化学式或 ID
|
||||
# Logger.info(get)
|
||||
soup = BeautifulSoup(get, 'html.parser') # 解析 HTML
|
||||
name = soup.find('span',
|
||||
|
@ -43,8 +44,8 @@ async def search_csr(id=None): # 根据 ChemSpider 的 ID 查询 ChemSpider 的
|
|||
wh = 500 * value // 100
|
||||
if wh < 500:
|
||||
wh = 500
|
||||
return {'name': name, 'image': f'https://www.chemspider.com/ImagesHandler.ashx?id={answer}' +
|
||||
(f"&w={wh}&h={wh}" if answer not in special_id else "")}
|
||||
return {'id': answer_id, 'name': name, 'image': f'https://www.chemspider.com/ImagesHandler.ashx?id={answer_id}' +
|
||||
(f"&w={wh}&h={wh}" if answer_id not in special_id else "")}
|
||||
|
||||
|
||||
cc = on_command('chemical_code', alias=['cc', 'chemicalcode'], desc='化学式验证码测试', developers=['OasisAkari'])
|
||||
|
@ -92,16 +93,31 @@ async def chemical_code(msg: MessageSession, id=None): # 要求传入消息会
|
|||
play_state[msg.target.targetId]['answer'] = csr['name'] # 将正确答案标记于 play_state 中存储的对象中
|
||||
Logger.info(f'Answer: {csr["name"]}') # 在日志中输出正确答案
|
||||
Logger.info(f'Image: {csr["image"]}') # 在日志中输出图片链接
|
||||
download = await download_to_cache(csr['image']) # 从结果中获取链接并下载图片
|
||||
download = False
|
||||
if csr["id"] in special_id: # 如果正确答案在 special_id 中
|
||||
file_path = os.path.abspath(f'./assets/chemicalcode/special_id/{csr["id"]}.png')
|
||||
Logger.info(f'File path: {file_path}') # 在日志中输出文件路径
|
||||
exists_file = os.path.exists(file_path) # 尝试获取图片文件是否存在
|
||||
if exists_file:
|
||||
download = file_path
|
||||
if not download:
|
||||
download = await download_to_cache(csr['image']) # 从结果中获取链接并下载图片
|
||||
|
||||
with PILImage.open(download) as im: # 打开下载的图片
|
||||
im.convert("RGBA")
|
||||
datas = im.getdata() # 获取图片数组
|
||||
newData = []
|
||||
for item in datas: # 对每个像素点进行处理
|
||||
if item[3] == 0: # 如果为透明
|
||||
newData.append((230, 230, 230)) # 设置白底
|
||||
if isinstance(item, int):
|
||||
if item == 0:
|
||||
newData.append((230, 230, 230))
|
||||
else:
|
||||
newData.append(item)
|
||||
else:
|
||||
newData.append(tuple(item[:3])) # 否则保留原图像素点
|
||||
if item[3] == 0:
|
||||
newData.append((230, 230, 230))
|
||||
else:
|
||||
newData.append(tuple(item[:3])) # 否则保留原图像素点
|
||||
image = PILImage.new("RGBA", im.size) # 创建新图片
|
||||
image.getdata() # 获取新图片数组
|
||||
image.putdata(newData) # 将处理后的数组覆盖新图片
|
||||
|
|