fix(songs): skip pages with existing non-auto-generated content #2

Merged
mikkeli merged 1 commits from automation/songs into main 2026-06-09 09:31:02 +00:00
Showing only changes of commit 65aa617935 - Show all commits
+18 -4
View File
@@ -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
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__":