[Instagram Reels] Phase 2 완성 - instagram_bot.py: publish_reels() 추가 (MP4 → Reels API) - upload_video_container(), wait_for_video_ready() 구현 - 로컬 경로 → 공개 URL 자동 변환 (image_host.get_public_video_url()) - scheduler.py: job_distribute_instagram_reels() 추가 (10:30) - image_host.py: get_public_video_url() + 로컬 비디오 서버 추가 - VIDEO_HOST_BASE_URL 환경변수 지원 (Tailscale/CDN) [writer_bot.py] 신규 — 독립 실행형 글쓰기 봇 - api_content.py manual-write 엔드포인트에서 subprocess 호출 가능 - run_pending(): 오늘 날짜 미처리 글감 자동 처리 - run_from_topic(): 직접 주제 지정 - run_from_file(): JSON 파일 지정 - CLI: python bots/writer_bot.py [--topic "..." | --file path.json | --limit N] [보조 시스템 신규] v3.1 CLI + Assist 모드 - blog.cmd: venv Python 경유 Windows 런처 - blog_runtime.py + runtime_guard.py: 실행 진입점 + venv 검증 - blog_engine_cli.py: 대시보드 API 기반 CLI (blog status, blog review 등) - bots/assist_bot.py: URL 기반 수동 어시스트 파이프라인 - dashboard/backend/api_assist.py + frontend/Assist.jsx: 수동모드 탭 [engine_loader.py] v3.1 개선 - OpenClawWriter: --json 플래그 + payloads 파싱 + plain text 폴백 - ClaudeWebWriter: Playwright 쿠키 세션 (Cloudflare 차단으로 현재 비활성) - GeminiWebWriter: gemini-webapi 비공식 클라이언트 [scheduler.py] v3.1 개선 - _call_openclaw(): 플레이스홀더 → EngineLoader 실제 호출 - _build_openclaw_prompt(): 구조화된 HTML 원고 프롬프트 - data/originals/: 원본 article JSON 저장 경로 추가 [설정/환경] 정비 - .env.example: SEEDANCE/ELEVENLABS/GEMINI/RUNWAY 복원 + VIDEO_HOST_BASE_URL, GEMINI_WEB_* , REMOTE_CLAUDE_POLLING_ENABLED 추가 - scripts/setup.bat: data/originals, outputs, assist, novels, config/novels 디렉토리 생성 + 폰트 다운로드 + blog.cmd 기반 Task Scheduler 등록 - requirements.txt: fastapi, uvicorn, python-multipart 추가 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
108 lines
3.1 KiB
Python
108 lines
3.1 KiB
Python
"""
|
|
Shared runtime checks and project-Python helpers.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import importlib.metadata
|
|
import os
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parent
|
|
REQUIREMENTS_FILE = PROJECT_ROOT / "requirements.txt"
|
|
VENV_DIR = PROJECT_ROOT / "venv"
|
|
|
|
|
|
def project_python_path() -> Path:
|
|
if os.name == "nt":
|
|
return VENV_DIR / "Scripts" / "python.exe"
|
|
return VENV_DIR / "bin" / "python"
|
|
|
|
|
|
def _normalized(path: str | Path) -> str:
|
|
return str(Path(path).resolve()).casefold()
|
|
|
|
|
|
def _parse_requirement_name(line: str) -> str | None:
|
|
stripped = line.strip()
|
|
if not stripped or stripped.startswith("#"):
|
|
return None
|
|
requirement = stripped.split(";", 1)[0].strip()
|
|
requirement = re.split(r"[<>=!~]", requirement, 1)[0].strip()
|
|
return requirement or None
|
|
|
|
|
|
def load_required_distributions() -> list[str]:
|
|
if not REQUIREMENTS_FILE.exists():
|
|
return []
|
|
|
|
packages: list[str] = []
|
|
for line in REQUIREMENTS_FILE.read_text(encoding="utf-8").splitlines():
|
|
name = _parse_requirement_name(line)
|
|
if name:
|
|
packages.append(name)
|
|
return packages
|
|
|
|
|
|
def missing_distributions(distributions: list[str]) -> list[str]:
|
|
missing: list[str] = []
|
|
for name in distributions:
|
|
try:
|
|
importlib.metadata.version(name)
|
|
except importlib.metadata.PackageNotFoundError:
|
|
missing.append(name)
|
|
return missing
|
|
|
|
|
|
def ensure_project_runtime(
|
|
entrypoint: str,
|
|
required_distributions: list[str] | None = None,
|
|
) -> None:
|
|
expected_python = project_python_path()
|
|
current_python = Path(sys.executable)
|
|
|
|
if not expected_python.exists():
|
|
raise RuntimeError(
|
|
f"{entrypoint} requires the project virtualenv at '{expected_python}'. "
|
|
"Create it first and install requirements.txt."
|
|
)
|
|
|
|
if _normalized(current_python) != _normalized(expected_python):
|
|
raise RuntimeError(
|
|
f"{entrypoint} must run with the project virtualenv Python.\n"
|
|
f"Current: {current_python}\n"
|
|
f"Expected: {expected_python}\n"
|
|
f"Safe path: {expected_python} {PROJECT_ROOT / 'blog_runtime.py'} "
|
|
f"{_default_launcher_arg(entrypoint)}"
|
|
)
|
|
|
|
missing = missing_distributions(required_distributions or [])
|
|
if missing:
|
|
raise RuntimeError(
|
|
f"{entrypoint} is missing required packages in the project virtualenv: "
|
|
f"{', '.join(missing)}\n"
|
|
f"Install with: {expected_python} -m pip install -r {REQUIREMENTS_FILE}"
|
|
)
|
|
|
|
|
|
def run_with_project_python(args: list[str], **kwargs) -> subprocess.CompletedProcess:
|
|
ensure_project_runtime("project subprocess")
|
|
cmd = [str(project_python_path()), *args]
|
|
return subprocess.run(cmd, **kwargs)
|
|
|
|
|
|
def project_python_cmd(args: list[str]) -> list[str]:
|
|
return [str(project_python_path()), *args]
|
|
|
|
|
|
def _default_launcher_arg(entrypoint: str) -> str:
|
|
lowered = entrypoint.lower()
|
|
if "scheduler" in lowered:
|
|
return "scheduler"
|
|
if "server" in lowered or "dashboard" in lowered:
|
|
return "server"
|
|
return "status"
|