diff --git a/post_parser.py b/post_parser.py index 17ec022..0ab04d1 100644 --- a/post_parser.py +++ b/post_parser.py @@ -204,7 +204,7 @@ class PostParser: html_content.append(f'
{text}
') if not naked: - if reactions_views_html := self._format_reactions_and_views(message): # Add reactions and views + if reactions_views_html := self._reactions_views_links(message): # Add reactions, views and links html_content.append(reactions_views_html) if not naked: @@ -275,21 +275,27 @@ class PostParser: html_content = '\n'.join(struct) return html_content - def _format_reactions_and_views(self, message: Message) -> Union[str, None]: + def _reactions_views_links(self, message: Message) -> Union[str, None]: try: html_parts = [] html_parts.append("
") - if reactions := getattr(message, "reactions", None): + if reactions := getattr(message, "reactions", None): #add reactions reactions_html = '' for reaction in reactions.reactions: reactions_html += f'{reaction.emoji} {reaction.count} ' html_parts.append(reactions_html) - if views := getattr(message, "views", None): + if views := getattr(message, "views", None): #add views views_html = f'(Views: {views})' html_parts.append(views_html) + if message.chat.username: #add links to telegram and web + tg_link = f'
Open in Telegram' + html_parts.append(tg_link) + tg_web_link = f'
Open in Web' + html_parts.append(tg_web_link) + html = ' '.join(html_parts) if html_parts else None return html