From 65aa617935fffffe221dab95da0ac28a29e1418f Mon Sep 17 00:00:00 2001 From: Mikkeli Matlock Date: Tue, 9 Jun 2026 18:23:14 +0900 Subject: [PATCH] fix(songs): skip pages with existing non-auto-generated content If a wiki page exists but was written manually (no Auto-generated banner), the bot now skips it instead of attempting an overwrite that triggers MediaWiki CAPTCHA. Clear stderr warning tells user to delete the page or add the banner to hand ownership to the bot. Co-Authored-By: Claude Sonnet 4.6 --- pipelines/songs/render.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/pipelines/songs/render.py b/pipelines/songs/render.py index c7dfc44..926b8ad 100644 --- a/pipelines/songs/render.py +++ b/pipelines/songs/render.py @@ -76,15 +76,23 @@ def connect_wiki() -> mwclient.Site: return site +AUTO_BANNER_PREFIX = "{{Auto-generated" + + def publish_one(rel: Path, post, site: mwclient.Site, source_ref: str, gitea_repo_url: str) -> str: - """Returns 'published' or 'noop'.""" + """Returns 'published', 'noop', or 'skipped-manual'.""" fm = post.metadata body_wikitext = markdown_to_wikitext(strip_first_h1(post.content)) source_url = f"{gitea_repo_url}/src/commit/{source_ref}/{rel}" page_content = build_wikitext(fm, body_wikitext, source_url, source_ref) page = site.pages[fm["title"]] - if page.text() == page_content: + existing = page.text() + + if existing and not existing.startswith(AUTO_BANNER_PREFIX): + return "skipped-manual" + + if existing == page_content: return "noop" ref_short = source_ref[:8] if source_ref else "unknown" @@ -157,14 +165,20 @@ def main() -> None: site = connect_wiki() - counts = {"published": 0, "noop": 0} + counts = {"published": 0, "noop": 0, "skipped-manual": 0} for abs_path, post in posts.items(): rel = abs_path.relative_to(source_dir) outcome = publish_one(rel, post, site, source_ref, gitea_repo_url) counts[outcome] += 1 - print(f" [{outcome}] {rel}") + if outcome == "skipped-manual": + print(f" [skipped-manual] {rel} ← page exists without auto-gen banner; delete or add banner to hand over to bot", file=sys.stderr) + else: + print(f" [{outcome}] {rel}") - print(f"\nDone: {counts['published']} published, {counts['noop']} unchanged.") + print( + f"\nDone: {counts['published']} published, {counts['noop']} unchanged, " + f"{counts['skipped-manual']} skipped (existing manual pages)." + ) if __name__ == "__main__":