fix(songs): skip pages with existing non-auto-generated content #2
@@ -76,15 +76,23 @@ def connect_wiki() -> mwclient.Site:
|
|||||||
return 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:
|
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
|
fm = post.metadata
|
||||||
body_wikitext = markdown_to_wikitext(strip_first_h1(post.content))
|
body_wikitext = markdown_to_wikitext(strip_first_h1(post.content))
|
||||||
source_url = f"{gitea_repo_url}/src/commit/{source_ref}/{rel}"
|
source_url = f"{gitea_repo_url}/src/commit/{source_ref}/{rel}"
|
||||||
page_content = build_wikitext(fm, body_wikitext, source_url, source_ref)
|
page_content = build_wikitext(fm, body_wikitext, source_url, source_ref)
|
||||||
|
|
||||||
page = site.pages[fm["title"]]
|
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"
|
return "noop"
|
||||||
|
|
||||||
ref_short = source_ref[:8] if source_ref else "unknown"
|
ref_short = source_ref[:8] if source_ref else "unknown"
|
||||||
@@ -157,14 +165,20 @@ def main() -> None:
|
|||||||
|
|
||||||
site = connect_wiki()
|
site = connect_wiki()
|
||||||
|
|
||||||
counts = {"published": 0, "noop": 0}
|
counts = {"published": 0, "noop": 0, "skipped-manual": 0}
|
||||||
for abs_path, post in posts.items():
|
for abs_path, post in posts.items():
|
||||||
rel = abs_path.relative_to(source_dir)
|
rel = abs_path.relative_to(source_dir)
|
||||||
outcome = publish_one(rel, post, site, source_ref, gitea_repo_url)
|
outcome = publish_one(rel, post, site, source_ref, gitea_repo_url)
|
||||||
counts[outcome] += 1
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user