Refactor code

This commit is contained in:
2023-01-29 01:08:40 +01:00
parent 155b94cff2
commit ae702fe492
3 changed files with 61 additions and 69 deletions

View File

@ -22,7 +22,7 @@ from discord_rss_bot.custom_message import (
CustomEmbed,
get_custom_message,
get_embed,
get_images_from_entry,
get_image,
replace_tags_in_text_message,
save_embed,
)
@ -396,10 +396,13 @@ def create_html_for_feed(entries: Iterable[Entry]) -> str:
html: str = ""
for entry in entries:
first_image = ""
first_image_text = ""
if images := get_images_from_entry(entry=entry):
first_image: str = images[0][0]
first_image_text: str = images[0][1]
summary: str | None = entry.summary
content = ""
if entry.content:
for content_item in entry.content:
content: str = content_item.value
first_image = get_image(summary, content)
text: str = replace_tags_in_text_message(entry) or "<div class='text-muted'>No content available.</div>"
published = ""
@ -416,7 +419,7 @@ def create_html_for_feed(entries: Iterable[Entry]) -> str:
entry_id: str = urllib.parse.quote(entry.id)
to_disord_html: str = f"<a class='text-muted' href='/post_entry?entry_id={entry_id}'>Send to Discord</a>"
image_html: str = f"<img src='{first_image}' class='img-fluid' alt='{first_image_text}'>" if first_image else ""
image_html: str = f"<img src='{first_image}' class='img-fluid'>" if first_image else ""
html += f"""<div class="p-2 mb-2 border border-dark">
{blacklisted}{whitelisted}<a class="text-muted text-decoration-none" href="{entry.link}"><h2>{entry.title}</h2></a>