automation/songs #1

Merged
mikkeli merged 6 commits from automation/songs into main 2026-06-09 09:03:36 +00:00
Showing only changes of commit df7195511f - Show all commits
+4 -5
View File
@@ -5,7 +5,7 @@ import argparse
import os import os
import subprocess import subprocess
import sys import sys
from datetime import datetime, timezone from datetime import datetime
from pathlib import Path from pathlib import Path
import frontmatter import frontmatter
@@ -60,9 +60,8 @@ def markdown_to_wikitext(body: str) -> str:
return result.stdout return result.stdout
def build_wikitext(fm: dict, body_wikitext: str, source_url: str) -> str: def build_wikitext(fm: dict, body_wikitext: str, source_url: str, source_ref: str) -> str:
now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ") banner = f"{{{{Auto-generated|source={source_url}|commit={source_ref}}}}}"
banner = f"{{{{Auto-generated|source={source_url}|generated_at={now}}}}}"
category = f"[[Category:{fm['album']}]]" category = f"[[Category:{fm['album']}]]"
return f"{banner}\n\n{body_wikitext}\n{category}\n" return f"{banner}\n\n{body_wikitext}\n{category}\n"
@@ -89,7 +88,7 @@ def publish_one(rel: Path, post, site: mwclient.Site, source_ref: str, gitea_rep
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) 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: if page.text() == page_content: