77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
|
|
import json
|
||
|
|
import os
|
||
|
|
import shutil
|
||
|
|
import uuid
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
from loguru import logger
|
||
|
|
|
||
|
|
import spider.task as task_module
|
||
|
|
|
||
|
|
|
||
|
|
# 直接在这里填写测试参数
|
||
|
|
COOKIES = {"c_user":"61586392053773","datr":"WV6nae8OJRICxw_kijnEpLD1","fr":"0hGCJPLgNUFLUrV6Z.AWcsvWymOjMTEFtBgLfY-pw-Xz-P97RXobgVcM284eq3bj35ub4.Bpp16Z..AAA.0.0.Bpp16Z.AWdJOJ9zB5VzOioMAXgv9kW9VqE","xs":"29:Tu729Jl28NcUNQ:2:1772576414:-1:-1"}
|
||
|
|
|
||
|
|
CONTENT = "International rankings consistently place the Philippines high on corruption perception. This damages foreign investment and our global standing. Let's change this narrative.#PoliticalDynastyCorruption"
|
||
|
|
|
||
|
|
LOCAL_VIDEO_PATH = r"E:\Code\Python\facebook\files\e2b8eaad-f950-46b6-9268-634d697f1ac9.mp4"
|
||
|
|
|
||
|
|
DRY_RUN = False
|
||
|
|
|
||
|
|
|
||
|
|
def _validate_config():
|
||
|
|
missing = [key for key, value in COOKIES.items() if not str(value).strip()]
|
||
|
|
if missing:
|
||
|
|
raise ValueError(f"cookies 缺少字段: {', '.join(missing)}")
|
||
|
|
|
||
|
|
if not CONTENT.strip():
|
||
|
|
raise ValueError("CONTENT 不能为空")
|
||
|
|
|
||
|
|
if not LOCAL_VIDEO_PATH.strip():
|
||
|
|
raise ValueError("LOCAL_VIDEO_PATH 不能为空")
|
||
|
|
|
||
|
|
video_path = Path(LOCAL_VIDEO_PATH)
|
||
|
|
if not video_path.exists():
|
||
|
|
raise FileNotFoundError(f"视频文件不存在: {video_path}")
|
||
|
|
|
||
|
|
if video_path.suffix.lower() != ".mp4":
|
||
|
|
raise ValueError(f"当前测试文件仅按 mp4 视频发布流程处理: {video_path}")
|
||
|
|
|
||
|
|
|
||
|
|
def _prepare_local_video(video_path_str):
|
||
|
|
source = Path(video_path_str)
|
||
|
|
temp_name = f"{uuid.uuid4()}_{source.name}"
|
||
|
|
target = Path(task_module.BASE_PATH) / "files" / temp_name
|
||
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
||
|
|
shutil.copy2(source, target)
|
||
|
|
return str(target)
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
_validate_config()
|
||
|
|
|
||
|
|
logger.add("./log/test_playwright_post.log", rotation="20 MB")
|
||
|
|
|
||
|
|
original_download = task_module._download_post_media
|
||
|
|
|
||
|
|
def _download_post_media_for_test(_image_key):
|
||
|
|
return _prepare_local_video(LOCAL_VIDEO_PATH)
|
||
|
|
|
||
|
|
task_module._download_post_media = _download_post_media_for_test
|
||
|
|
|
||
|
|
try:
|
||
|
|
result = task_module.playwright_post(
|
||
|
|
cookies=COOKIES,
|
||
|
|
content=CONTENT,
|
||
|
|
image_key=os.path.basename(LOCAL_VIDEO_PATH),
|
||
|
|
dry_run=DRY_RUN,
|
||
|
|
)
|
||
|
|
logger.info("发布结果: {}", result)
|
||
|
|
print(json.dumps(result, ensure_ascii=False, indent=2))
|
||
|
|
finally:
|
||
|
|
task_module._download_post_media = original_download
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|