diff --git a/post_parser.py b/post_parser.py index 68ff6b0..3829f2b 100644 --- a/post_parser.py +++ b/post_parser.py @@ -188,7 +188,8 @@ class PostParser: return f"π Poll: {poll_question}" return "π Poll" if message.media == MessageMediaType.DOCUMENT: - if message.document is not None and hasattr(message.document, 'mime_type') and message.document.mime_type == 'application/pdf': + is_mime = (message.document is not None and hasattr(message.document, 'mime_type')) + if is_mime and message.document is not None and message.document.mime_type == 'application/pdf': return "π PDF Document" return "π Document" if message.media == MessageMediaType.PHOTO: return "π· Photo" @@ -279,13 +280,15 @@ class PostParser: def _format_reply_info(self, message: Message) -> Union[str, None]: - if getattr(message, "service", None) and 'PINNED_MESSAGE' in str(message.service) and (reply_to := getattr(message, "reply_to_message", None)): + is_pinned = (getattr(message, "service", None) and 'PINNED_MESSAGE' in str(message.service)) + reply_to = getattr(message, "reply_to_message", None) + if is_pinned and reply_to: reply_text = reply_to.text or reply_to.caption or '' if len(reply_text) > 100: reply_text = reply_text[:100] + '...' return f'
{data["raw_message"]}')
+ html_content.append(f'{data["raw_message"]}')
html_data = '\n'.join(html_content)
return html_data
@@ -497,7 +507,10 @@ class PostParser:
def _sanitize_html(self, html_raw: str) -> str:
- allowed_tags = ['p', 'a', 'b', 'i', 'strong', 'em', 'ul', 'ol', 'li', 'br', 'div', 'span', 'img', 'video', 'audio', 'source']
+ allowed_tags = ['p', 'a', 'b', 'i', 'strong',
+ 'em', 'ul', 'ol', 'li', 'br',
+ 'div', 'span', 'img', 'video', 'audio',
+ 'source']
allowed_attributes = {
'a': ['href', 'title', 'target'],
'img': ['src', 'alt', 'style'],
@@ -622,38 +635,52 @@ class PostParser:
content_media.append(f'')
if webpage := getattr(message, "web_page", None): # Web page preview
@@ -674,7 +701,9 @@ class PostParser:
if is_telegram_message:
# Telegram message preview with distinctive styling
- html_parts = ['