automation/songs #1
@@ -5,7 +5,7 @@ import argparse
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
import frontmatter
|
||||
@@ -60,9 +60,8 @@ def markdown_to_wikitext(body: str) -> str:
|
||||
return result.stdout
|
||||
|
||||
|
||||
def build_wikitext(fm: dict, body_wikitext: str, source_url: str) -> str:
|
||||
now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
banner = f"{{{{Auto-generated|source={source_url}|generated_at={now}}}}}"
|
||||
def build_wikitext(fm: dict, body_wikitext: str, source_url: str, source_ref: str) -> str:
|
||||
banner = f"{{{{Auto-generated|source={source_url}|commit={source_ref}}}}}"
|
||||
category = f"[[Category:{fm['album']}]]"
|
||||
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))
|
||||
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"]]
|
||||
if page.text() == page_content:
|
||||
|
||||
Reference in New Issue
Block a user