23 lines
682 B
Python
23 lines
682 B
Python
|
|
from app.captions import normalize_article_captions
|
||
|
|
from app.database import SessionLocal, init_db
|
||
|
|
from app.models import Article
|
||
|
|
|
||
|
|
|
||
|
|
def main() -> None:
|
||
|
|
init_db()
|
||
|
|
changed = 0
|
||
|
|
with SessionLocal() as session:
|
||
|
|
articles = session.query(Article).order_by(Article.id.asc()).all()
|
||
|
|
for article in articles:
|
||
|
|
normalized = normalize_article_captions(article.body_html or "", article.title)
|
||
|
|
if normalized == (article.body_html or ""):
|
||
|
|
continue
|
||
|
|
article.body_html = normalized
|
||
|
|
changed += 1
|
||
|
|
session.commit()
|
||
|
|
print(f"Updated article captions: {changed}")
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|