Refine author display formatting in RSS and PostParser

This commit is contained in:
vvzvlad
2025-02-05 03:17:17 +03:00
parent e4d7fa402b
commit cd06bb1e14
2 changed files with 4 additions and 6 deletions
+2 -2
View File
@@ -102,13 +102,13 @@ class PostParser:
if message.sender_chat:
title = getattr(message.sender_chat, 'title', '').strip()
username = getattr(message.sender_chat, 'username', '').strip()
return f"{title} by @{username}" if username else title
return f"{title} (@{username})" if username else title
elif message.from_user:
first = getattr(message.from_user, 'first_name', '').strip()
last = getattr(message.from_user, 'last_name', '').strip()
username = getattr(message.from_user, 'username', '').strip()
name = ' '.join(filter(None, [first, last]))
return f"{name} by @{username}" if username else name
return f"{name} (@{username})" if username else name
return "Unknown author"
def _generate_title(self, message: Message) -> str:
+2 -4
View File
@@ -50,9 +50,7 @@ async def generate_channel_rss(channel: str, post_parser: Optional[PostParser] =
fg.link(href=f"https://t.me/{channel}", rel='alternate')
fg.description(f'Telegram channel {channel} RSS feed')
fg.language('ru')
#fg.dc.dc_creator(f"@{channel}")
fg.id(f"{base_url}/rss/{channel}")
# First collect all posts
@@ -127,7 +125,7 @@ async def generate_channel_rss(channel: str, post_parser: Optional[PostParser] =
fe.pubDate(pub_date)
fe.guid(post_link, permalink=True)
if post.get('author') and post['author'] != channel:
if post.get('author') and post['author'] != main_name:
fe.author(name="", email=post['author'])
rss_feed = fg.rss_str(pretty=True)