Add channel title and icon to RSS feed generation
This commit is contained in:
+8
-1
@@ -129,11 +129,18 @@ async def get_rss_feed(channel: str):
|
||||
|
||||
# Create FeedGenerator
|
||||
fg = FeedGenerator()
|
||||
fg.title(channel)
|
||||
channel_title = posts[0].get('channel_title', channel) if posts else channel
|
||||
channel_icon = posts[0].get('channel_icon', '') if posts else ''
|
||||
|
||||
fg.title(channel_title)
|
||||
fg.link(href=f"https://t.me/{channel}", rel='alternate')
|
||||
fg.description(f'Telegram channel {channel} RSS feed')
|
||||
fg.language('ru-ru')
|
||||
|
||||
if channel_icon:
|
||||
fg.logo(f"{settings['pyrogram_bridge_url']}/media/{channel_icon}")
|
||||
fg.icon(f"{settings['pyrogram_bridge_url']}/media/{channel_icon}")
|
||||
|
||||
# Add channel metadata
|
||||
fg.id(f"{settings['pyrogram_bridge_url']}/rss/{channel}")
|
||||
fg.link(href=f"{settings['pyrogram_bridge_url']}/rss/{channel}", rel='self', type='application/rss+xml')
|
||||
|
||||
+10
-1
@@ -542,15 +542,24 @@ class TelegramClient:
|
||||
await self.start()
|
||||
|
||||
posts = []
|
||||
channel_title = ""
|
||||
channel_icon = ""
|
||||
async for message in self.client.get_chat_history(
|
||||
chat_id=channel,
|
||||
limit=limit
|
||||
):
|
||||
if not channel_title and message.sender_chat:
|
||||
channel_title = getattr(message.sender_chat, "title", channel)
|
||||
if hasattr(message.sender_chat, "photo") and message.sender_chat.photo:
|
||||
channel_icon = message.sender_chat.photo.small_file_id
|
||||
|
||||
parsed = await self._parse_message(message)
|
||||
if parsed and parsed.get('html'): # Skip None and empty
|
||||
if parsed and parsed.get('html'):
|
||||
posts.append({
|
||||
"id": message.id,
|
||||
"date": message.date,
|
||||
"channel_title": channel_title,
|
||||
"channel_icon": channel_icon,
|
||||
"title": self._generate_title(parsed.get("raw_text", "")),
|
||||
"html": parsed["html"],
|
||||
"media": parsed.get("media", [])
|
||||
|
||||
Reference in New Issue
Block a user