diff --git a/post_parser.py b/post_parser.py index 1b8d416..842de8f 100644 --- a/post_parser.py +++ b/post_parser.py @@ -325,7 +325,11 @@ class PostParser: flags = self._extract_flags(message) if flags: - return f'🏷 {" 🏷".join(flags)}' + flags_html = ['
'] + for flag in flags: + flags_html.append(f'🏷 {flag}') + flags_html.append('
') + return ' '.join(flags_html) return '' def process_message(self, message: Message) -> Dict[Any, Any]: @@ -575,52 +579,52 @@ class PostParser: try: parts = [] + # First line: reactions + views + date + first_line_parts = [] + + # Add reactions reactions_html = "" - views_html = "" if reactions := getattr(message, "reactions", None): for reaction in reactions.reactions: # 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} ' - reactions_html = reactions_html.strip() + reactions_html += f'{emoji} {reaction.count}  ' + reactions_html = reactions_html.rstrip() + first_line_parts.append(reactions_html) + # Add views if views := getattr(message, "views", None): - views_html = f'{views} 👁' + first_line_parts.append(f'{views} 👁') - # Combine reactions and views on the same line - if reactions_html or views_html: - parts.append(f'{reactions_html} | {views_html}') - - # Add date and links on the same line - second_line_parts = [] - - # Format date as DD/MM/YY, HH:MM:SS + # Add date if message.date: formatted_date = message.date.strftime("%d/%m/%y, %H:%M:%S") - second_line_parts.append(formatted_date) + first_line_parts.append(formatted_date) - # Add links + if first_line_parts: + parts.append('  |  '.join(first_line_parts)) + + # Second line: links channel_identifier = self.get_channel_username(message) if channel_identifier: links = [] base_url = Config['pyrogram_bridge_url'] - if channel_identifier.startswith('-100'): # For channels with only ID - channel_id = channel_identifier[4:] # Remove '-100' prefix for web links - links.append(f'Open in Telegram') - links.append(f'Open in Web') - else: # For channels with username - links.append(f'Open in Telegram') - links.append(f'Open in Web') + if channel_identifier.startswith('-100'): + channel_id = channel_identifier[4:] + links.append(f'Open in Telegram') + links.append(f'Open in Web') + else: + links.append(f'Open in Telegram') + links.append(f'Open in Web') if Config['show_bridge_link']: token = Config['token'] - links.append(f'Open in Bridge') - second_line_parts.extend(links) - - if second_line_parts: - parts.append(' | '.join(second_line_parts)) + links.append(f'Open in Bridge') + + if links: + parts.append(' | '.join(links)) result_html = '
'.join(parts) if parts else None return self._sanitize_html(result_html) if result_html else None