""".strip()
def is_po_suti_dela_article(article: Article) -> bool:
if not article.video:
return False
text = f"{article.video.title or ''}\n{article.video.description or ''}".lower()
return "по сути дела" in text
def cultural_initiatives_html() -> str:
return """
)',
html or "",
flags=re.I | re.S,
)
if not match:
return html or "", ""
body_html = f"{html[:match.start()]}{html[match.end():]}".strip()
return body_html, match.group(1).strip()
def media_player_xml(article: Article) -> str:
if not article.video or not article.video.source_url:
return ""
embed_url = vk_video_embed_url(article.video.source_url)
if not embed_url:
return ""
return f''
def render_article_html(article: Article, include_video_embed: bool = True, rss_safe: bool = False) -> str:
body_html = strip_article_cover_html(article.body_html)
body_html, audience_question_html = split_audience_question_html(body_html)
body_html = sanitize_rss_html(body_html) if rss_safe else body_html
parts = [article.lead, cover_html(article, rss_safe=rss_safe), body_html]
if include_video_embed:
parts.append(video_embed_html(article, rss_safe=rss_safe))
if audience_question_html:
parts.append(audience_question_html)
if article.cta_html:
parts.append(article.cta_html)
html = "\n".join(part for part in parts if part).strip()
html = strip_leading_duplicate_title(html, article.title)
return sanitize_rss_html(html) if rss_safe else html
def build_feed_xml(session: Session, settings: Settings) -> str:
now = datetime.now(timezone.utc)
articles = session.scalars(
select(Article)
.where(Article.status == "published", Article.published_at.is_not(None), Article.published_at <= now)
.order_by(Article.published_at.desc(), Article.id.desc())
.limit(settings.rss_limit)
).all()
items: list[str] = []
for article in articles:
link = article_url(settings, article)
content = f"
{escape(article.title)}
\n{render_article_html(article, rss_safe=True)}"
frames = []
if article.video_id:
frames = session.scalars(
select(Frame)
.where(Frame.video_id == article.video_id, Frame.selected == True) # noqa: E712
.order_by(Frame.score.desc(), Frame.id.asc())
.limit(1)
).all()
enclosure = ""
cover_url = article_feature_image_url(article)
if cover_url:
enclosure = f''
elif frames and frames[0].public_url:
enclosure = f''
media_player = media_player_xml(article)
items.append(
f"""
{escape(article.title)}
{escape(link)}
{escape(article.rss_guid or link)}{rfc822(article.published_at)}format-articleindexcomment-allnonadult
{media_player}
{enclosure}
""".strip()
)
return f"""
Николай Стариков
{escape(settings.public_base_url)}
Автоматические материалы канала Николая Старикова для Дзенаru{rfc822(datetime.now(timezone.utc))}
{chr(10).join(items)}
"""