From 0d94ff9e1ad3730bb520466419346487fca1ef37 Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Thu, 27 Mar 2025 18:21:40 +0300 Subject: [PATCH] Enhance PostParser with CSS styles for reactions string --- post_parser.py | 61 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/post_parser.py b/post_parser.py index ecfe86c..ecb146c 100644 --- a/post_parser.py +++ b/post_parser.py @@ -306,6 +306,42 @@ class PostParser: html_content = [] data = self.process_message(message)['html'] + # Add CSS styles + html_content.append(''' + +''') + html_content.append(f'
{data["header"]}
') html_content.append(f'
{data["media"]}
') html_content.append(f'
{data["body"]}
') @@ -325,7 +361,7 @@ class PostParser: flags = self._extract_flags(message) if flags: - return f'
Flags: {", ".join(flags)}
' + return f'🏷 {", ".join(flags)}' return '' def process_message(self, message: Message) -> Dict[Any, Any]: @@ -575,6 +611,7 @@ class PostParser: try: parts = [] + # First line: reactions and views reactions_html = "" views_html = "" if reactions := getattr(message, "reactions", None): @@ -582,24 +619,24 @@ class PostParser: # Replace None or empty emoji with replacement character emoji = reaction.emoji if emoji is None or emoji == "None" or emoji == "": - emoji = "�" # Question mark as replacement for missing emojis - reactions_html += f'{emoji} {reaction.count}  ' + emoji = "��" # Question mark as replacement for missing emojis + reactions_html += f'{emoji} {reaction.count}' reactions_html = reactions_html.rstrip() if views := getattr(message, "views", None): - views_html = f'{views} views' + views_html = f'👁 {views}' - # Combine reactions and views on the same line + # Combine reactions and views with proper spacing if reactions_html or views_html: - parts.append(f'{reactions_html}  {views_html}') + parts.append(f'
{reactions_html} {views_html}
') - # Add date and links on the same line + # Second line: date and links second_line_parts = [] # Format date as DD/MM/YY, HH:MM:SS if message.date: formatted_date = message.date.strftime("%d/%m/%y, %H:%M:%S") - second_line_parts.append(formatted_date) + second_line_parts.append(f'{formatted_date}') # Add links channel_identifier = self.get_channel_username(message) @@ -620,9 +657,13 @@ class PostParser: second_line_parts.extend(links) if second_line_parts: - parts.append('    '.join(second_line_parts)) + parts.append(f'') - result_html = '
'.join(parts) if parts else None + # Third line: flags (if any) + if flags := self._format_flags(message): + parts.append(f'
{flags}
') + + result_html = '\n'.join(parts) if parts else None return self._sanitize_html(result_html) if result_html else None except Exception as e: