"""No bylines on articles."""
import re
from app.database import SessionLocal
from app.models.article import Article
from app.services import article_service

BYLINE = re.compile(r"\n*\*By Daniel Onyejesi[^*]*\*\s*$")

db = SessionLocal()
for slug in ["respiratory-failure", "pediatric-fracture-eponyms",
             "high-frequency-ventilation-physics", "the-mole-concept"]:
    article = db.query(Article).filter(Article.slug == slug).first()
    if not article:
        continue
    before = article.content or ""
    article.content = BYLINE.sub("", before).rstrip()
    changed = article.content != before
    db.commit()
    if changed:
        article_service.reindex(db, article)
    print(f"{slug}: {'byline removed' if changed else 'nothing to remove'}")
