Skip to content

Commit

Permalink
Update preview link model
Browse files Browse the repository at this point in the history
  • Loading branch information
koval01 committed Dec 13, 2024
1 parent 11b35bb commit 57c3c8f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions app/telegram/models/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,16 @@ class PreviewLink(BaseModel):
Attributes:
title (Optional[str]): The title of the linked content, if available
url (HttpUrl): This URL of preview page
site_name (str): The name of the website or platform the link is from
site_name (Optional[str]): The name of the website or platform the link is from
description (Optional[ParsedAndRaw]): The description of the linked content,
containing both parsed text and raw HTML formats
thumb (HttpUrl): The URL of the preview thumbnail image
thumb (Optional[HttpUrl]): The URL of the preview thumbnail image
"""
title: Optional[str]
url: HttpUrl
site_name: str
site_name: Optional[str]
description: Optional[ParsedAndRaw]
thumb: HttpUrl
thumb: Optional[HttpUrl]


class ContentPost(BaseModel):
Expand Down
3 changes: 2 additions & 1 deletion app/telegram/parser/types/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ def preview_link(buble: LexborNode) -> Union[dict, None]:
"html": Utils.get_text_html(description)
}

site_name = preview.css_first(".link_preview_site_name")
title = preview.css_first(".link_preview_title")
thumb = preview.css_first(".tgme_widget_message_link_preview > .link_preview_right_image")

return {
"site_name": preview.css_first(".link_preview_site_name").text(strip=True),
"site_name": site_name.text(strip=True) if site_name else None,
"url": preview.attributes.get("href"),
"title": title.text(strip=True) if title else None,
"description": description,
Expand Down

0 comments on commit 57c3c8f

Please sign in to comment.