Skip to content

Commit

Permalink
fix(*): TABLE_TO_IMAGE PhotoExtInvalidError
Browse files Browse the repository at this point in the history
Signed-off-by: Rongrong <i@rong.moe>
  • Loading branch information
Rongronggg9 committed Nov 13, 2023
1 parent 41a32c6 commit af00db6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/parsing/html_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async def _parse_item(self, soup: Union[PageElement, BeautifulSoup, Tag, Navigab
columns = row.findAll(('td', 'th'))
if len(rows) > 1 and len(columns) > 1: # allow single-row or single-column tables
if env.TABLE_TO_IMAGE:
self.media.add(UploadedImage(convert_table_to_png(str(soup))))
self.media.add(UploadedImage(convert_table_to_png(str(soup)), 'table.png'))
return None
for j, column in enumerate(columns): # transpose single-row tables into single-column tables
row_content = await self._parse_item(column)
Expand Down
5 changes: 3 additions & 2 deletions src/parsing/medium.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,10 @@ class Animation(Image):
class UploadedImage(AbstractMedium):
type: str = IMAGE

def __init__(self, file: Union[bytes, BytesIO, Callable, Awaitable]):
def __init__(self, file: Union[bytes, BytesIO, Callable, Awaitable], file_name: str = None):
super().__init__()
self.file = file
self.file_name = file_name
self.uploaded_file: Union[InputFile, InputFileBig, None] = None

def telegramize(self) -> Optional[InputMediaUploadedPhoto]:
Expand Down Expand Up @@ -705,7 +706,7 @@ async def validate(self, flush: bool = False, *_, **__) -> bool:
raise ValueError(f'File must be bytes or BytesIO, got {type(self.file)}')
if isinstance(self.file, BytesIO):
self.file.seek(0)
self.uploaded_file = await env.bot.upload_file(self.file)
self.uploaded_file = await env.bot.upload_file(self.file, file_name=self.file_name)
if isinstance(self.file, BytesIO):
self.file.close()
self.valid = True
Expand Down

0 comments on commit af00db6

Please sign in to comment.