mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-07-15 12:43:00 +08:00
Merge branch 'main' into arknights
This commit is contained in:
commit
60ce3ccc9e
@ -68,7 +68,7 @@ class Weibo(Platform):
|
|||||||
|
|
||||||
def _get_text(self, raw_text: str) -> str:
|
def _get_text(self, raw_text: str) -> str:
|
||||||
text = raw_text.replace('<br />', '\n')
|
text = raw_text.replace('<br />', '\n')
|
||||||
return bs(text).text
|
return bs(text, 'html.parser').text
|
||||||
|
|
||||||
async def parse(self, raw_post: RawPost) -> Post:
|
async def parse(self, raw_post: RawPost) -> Post:
|
||||||
info = raw_post['mblog']
|
info = raw_post['mblog']
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import base64
|
import base64
|
||||||
import math
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from typing import NoReturn, Optional
|
from typing import NoReturn, Optional
|
||||||
@ -37,26 +36,24 @@ class Post:
|
|||||||
if len(self.pics) < 6:
|
if len(self.pics) < 6:
|
||||||
return
|
return
|
||||||
first_image = await self._pic_url_to_image(self.pics[0])
|
first_image = await self._pic_url_to_image(self.pics[0])
|
||||||
if abs(first_image.size[0] - first_image.size[1]) / first_image.size[0] > 0.05:
|
if first_image.size[0] != first_image.size[1]:
|
||||||
return
|
return
|
||||||
pic_size = first_image.size[0]
|
pic_size = first_image.size[0]
|
||||||
images = [first_image]
|
images = [first_image]
|
||||||
for pic in self.pics[1:]:
|
for pic in self.pics[1:]:
|
||||||
cur_image = await self._pic_url_to_image(pic)
|
cur_image = await self._pic_url_to_image(pic)
|
||||||
if abs(first_image.size[0] - pic_size) / pic_size > 0.05 or \
|
if cur_image.size[0] != pic_size or cur_image.size[1] != pic_size:
|
||||||
abs(first_image.size[1] - pic_size) / pic_size > 0.05:
|
|
||||||
break
|
break
|
||||||
images.append(cur_image)
|
images.append(cur_image)
|
||||||
logger.debug('{} images is same size'.format(len(images)))
|
|
||||||
if len(images) == 6:
|
if len(images) == 6:
|
||||||
matrix = (3, 2)
|
matrix = (3, 2)
|
||||||
self.pics = self.pics[6:]
|
self.pics = self.pics[6:]
|
||||||
elif len(images) == 9:
|
elif len(images) >= 9:
|
||||||
matrix = (3, 3)
|
matrix = (3, 3)
|
||||||
self.pics = self.pics[9:]
|
self.pics = self.pics[9:]
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
logger.info('trigger merge image with {} imgs'.format(len(images)))
|
logger.info('trigger merge image')
|
||||||
target = Image.new('RGB', (matrix[0] * pic_size, matrix[1] * pic_size))
|
target = Image.new('RGB', (matrix[0] * pic_size, matrix[1] * pic_size))
|
||||||
for y in range(matrix[1]):
|
for y in range(matrix[1]):
|
||||||
for x in range(matrix[0]):
|
for x in range(matrix[0]):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user