posts will be published immediately

This commit is contained in:
2026-02-08 17:52:18 -05:00
parent 02bc0ce81d
commit 8aee2bf813

View File

@@ -1,7 +1,8 @@
from __future__ import annotations from __future__ import annotations
import time import time
from typing import Dict, List, Set from datetime import datetime
from typing import Dict, List, Optional, Set
from .errors import WordPressError from .errors import WordPressError
from .models import EvaluationResult, PostPlan from .models import EvaluationResult, PostPlan
@@ -87,6 +88,8 @@ def _apply_post(post: PostPlan, wp: WordPressCLI, category_map: Dict[tuple[int,
parent = category_map[map_key] parent = category_map[map_key]
category_ids.append(parent) category_ids.append(parent)
created_on, last_modified = _normalize_post_dates(post.created_on, post.last_modified)
post_id = wp.find_post_id(post.identity) post_id = wp.find_post_id(post.identity)
if post_id is None: if post_id is None:
wp.create_post( wp.create_post(
@@ -95,8 +98,8 @@ def _apply_post(post: PostPlan, wp: WordPressCLI, category_map: Dict[tuple[int,
categories=category_ids, categories=category_ids,
tags=post.tags, tags=post.tags,
source_identity=post.identity, source_identity=post.identity,
created_on=post.created_on, created_on=created_on,
last_modified=post.last_modified, last_modified=last_modified,
author=post.author, author=post.author,
) )
return return
@@ -107,7 +110,39 @@ def _apply_post(post: PostPlan, wp: WordPressCLI, category_map: Dict[tuple[int,
content=post.html, content=post.html,
categories=category_ids, categories=category_ids,
tags=post.tags, tags=post.tags,
created_on=post.created_on, created_on=created_on,
last_modified=post.last_modified, last_modified=last_modified,
author=post.author, author=post.author,
) )
def _normalize_post_dates(
created_on: Optional[str],
last_modified: Optional[str],
) -> tuple[Optional[str], Optional[str]]:
if not created_on and not last_modified:
return created_on, last_modified
now = datetime.now()
created_dt = _parse_post_date(created_on)
modified_dt = _parse_post_date(last_modified)
if created_dt and created_dt > now:
created_dt = now
if modified_dt and modified_dt > now:
modified_dt = now
if created_dt and modified_dt and modified_dt < created_dt:
modified_dt = created_dt
created_str = created_dt.strftime("%Y-%m-%d %H:%M:%S") if created_dt else None
modified_str = modified_dt.strftime("%Y-%m-%d %H:%M:%S") if modified_dt else None
return created_str, modified_str
def _parse_post_date(value: Optional[str]) -> Optional[datetime]:
if not value:
return None
try:
return datetime.strptime(value, "%Y-%m-%d %H:%M:%S")
except ValueError:
return None