added local export support and refined program logic

This commit is contained in:
2026-02-08 05:30:55 -05:00
parent 8ee2b39809
commit 6565a8546f
11 changed files with 488 additions and 32 deletions

View File

@@ -60,6 +60,24 @@ class WordPressCLI:
tags.append(TagTerm(term_id=int(entry["term_id"]), name=entry["name"]))
return tags
def create_tag(self, name: str) -> int:
result = self._run(
[
"wp",
"term",
"create",
"post_tag",
name,
"--porcelain",
],
capture_output=True,
)
output = result.stdout.strip()
try:
return int(output)
except ValueError as exc:
raise WordPressError(f"Invalid tag id from wp cli: {output}") from exc
def create_category(self, name: str, parent: int) -> int:
result = self._run(
[
@@ -107,6 +125,9 @@ class WordPressCLI:
categories: List[int],
tags: List[str],
source_identity: str,
created_on: Optional[str] = None,
last_modified: Optional[str] = None,
author: Optional[str] = None,
) -> int:
payload = json.dumps({"_wp_materialize_source": source_identity})
args = [
@@ -122,6 +143,12 @@ class WordPressCLI:
f"--meta_input={payload}",
"--porcelain",
]
if created_on:
args.append(f"--post_date={created_on}")
if last_modified:
args.append(f"--post_modified={last_modified}")
if author:
args.append(f"--post_author={author}")
result = self._run(args, capture_output=True)
output = result.stdout.strip()
try:
@@ -136,6 +163,9 @@ class WordPressCLI:
content: str,
categories: List[int],
tags: List[str],
created_on: Optional[str] = None,
last_modified: Optional[str] = None,
author: Optional[str] = None,
) -> None:
args = [
"wp",
@@ -147,6 +177,12 @@ class WordPressCLI:
f"--post_category={','.join(str(cat) for cat in categories)}",
f"--tags_input={','.join(tags)}",
]
if created_on:
args.append(f"--post_date={created_on}")
if last_modified:
args.append(f"--post_modified={last_modified}")
if author:
args.append(f"--post_author={author}")
self._run(args)
def _run_json(self, cmd: List[str]):