| 1 | """ |
| 2 | 当前文件先保留为视频号 uploader 的调试入口 / 历史直连路径。 |
| 3 | |
| 4 | 注意: |
| 5 | 1. `uploader/tencent_uploader/main.py` 里的核心页面交互逻辑目前是骨架; |
| 6 | 2. 你需要自己补视频里的 `fill_title_and_tags` / `wait_for_upload_complete` / `set_thumbnail` / `submit_publish` 等方法; |
| 7 | 3. 你需要自己补图文里的 `switch_to_note_mode` / `upload_note_images` / `fill_note_title_and_tags` / `submit_publish` 等方法; |
| 8 | 3. 补完后,这个 example 就可以直接作为本地调试入口继续使用。 |
| 9 | """ |
| 10 | |
| 11 | import asyncio |
| 12 | from datetime import datetime, timedelta |
| 13 | from pathlib import Path |
| 14 | |
| 15 | from conf import BASE_DIR |
| 16 | from uploader.tencent_uploader.main import TENCENT_PUBLISH_STRATEGY_IMMEDIATE |
| 17 | from uploader.tencent_uploader.main import TENCENT_PUBLISH_STRATEGY_SCHEDULED |
| 18 | from uploader.tencent_uploader.main import TencentNote |
| 19 | from uploader.tencent_uploader.main import TencentVideo |
| 20 | |
| 21 | |
| 22 | ACCOUNT_FILE = Path(BASE_DIR / "cookies" / "tencent_uploader" / "account.json") |
| 23 | |
| 24 | |
| 25 | def upload_video_to_tencent(): |
| 26 | video_file = Path(BASE_DIR) / "videos" / "demo.mp4" |
| 27 | thumbnail_path = video_file.with_suffix(".png") |
| 28 | app = TencentVideo( |
| 29 | title="视频号视频示例", |
| 30 | file_path=str(video_file), |
| 31 | tags=["视频号", "自动上传", "调试入口"], |
| 32 | publish_strategy=TENCENT_PUBLISH_STRATEGY_IMMEDIATE, |
| 33 | publish_date=0, |
| 34 | account_file=str(ACCOUNT_FILE), |
| 35 | desc="这里是你后面准备填写的视频简介示例", |
| 36 | thumbnail_path=str(thumbnail_path) if thumbnail_path.exists() else None, |
| 37 | short_title="视频号示例", |
| 38 | category=None, |
| 39 | is_draft=False, |
| 40 | ) |
| 41 | asyncio.run(app.tencent_upload_video()) |
| 42 | |
| 43 | |
| 44 | def upload_video_to_tencent_scheduled(): |
| 45 | video_file = Path(BASE_DIR) / "videos" / "demo.mp4" |
| 46 | thumbnail_path = video_file.with_suffix(".png") |
| 47 | publish_time = (datetime.now() + timedelta(hours=3)).replace(second=0, microsecond=0) |
| 48 | app = TencentVideo( |
| 49 | title="视频号定时发布示例", |
| 50 | file_path=str(video_file), |
| 51 | tags=["视频号", "定时发布", "调试入口"], |
| 52 | publish_strategy=TENCENT_PUBLISH_STRATEGY_SCHEDULED, |
| 53 | publish_date=publish_time, |
| 54 | account_file=str(ACCOUNT_FILE), |
| 55 | desc="这里是定时发布的视频简介示例", |
| 56 | thumbnail_path=str(thumbnail_path) if thumbnail_path.exists() else None, |
| 57 | short_title="定时发布示例", |
| 58 | category=None, |
| 59 | is_draft=False, |
| 60 | ) |
| 61 | asyncio.run(app.tencent_upload_video()) |
| 62 | |
| 63 | |
| 64 | def upload_note_to_tencent(): |
| 65 | image_candidates = [ |
| 66 | Path(BASE_DIR) / "videos" / "demo.png", |
| 67 | Path(BASE_DIR) / "videos" / "demo1.png", |
| 68 | Path(BASE_DIR) / "videos" / "demo2.png", |
| 69 | ] |
| 70 | image_paths = [str(path) for path in image_candidates if path.exists()] |
| 71 | app = TencentNote( |
| 72 | image_paths=image_paths, |
| 73 | note="视频号图文内容示例 #图文调试", |
| 74 | tags=["视频号图文", "自动上传", "调试入口"], |
| 75 | publish_strategy=TENCENT_PUBLISH_STRATEGY_IMMEDIATE, |
| 76 | publish_date=0, |
| 77 | account_file=str(ACCOUNT_FILE), |
| 78 | title="视频号图文示例", |
| 79 | is_draft=False, |
| 80 | ) |
| 81 | asyncio.run(app.tencent_upload_note()) |
| 82 | |
| 83 | |
| 84 | def upload_note_to_tencent_scheduled(): |
| 85 | image_candidates = [ |
| 86 | Path(BASE_DIR) / "videos" / "demo.png", |
| 87 | Path(BASE_DIR) / "videos" / "demo1.png", |
| 88 | Path(BASE_DIR) / "videos" / "demo2.png", |
| 89 | ] |
| 90 | image_paths = [str(path) for path in image_candidates if path.exists()] |
| 91 | publish_time = (datetime.now() + timedelta(hours=3)).replace(second=0, microsecond=0) |
| 92 | app = TencentNote( |
| 93 | image_paths=image_paths, |
| 94 | note="视频号图文定时发布示例 #图文调试", |
| 95 | tags=["视频号图文", "定时发布", "调试入口"], |
| 96 | publish_strategy=TENCENT_PUBLISH_STRATEGY_SCHEDULED, |
| 97 | publish_date=publish_time, |
| 98 | account_file=str(ACCOUNT_FILE), |
| 99 | title="视频号图文定时示例", |
| 100 | is_draft=False, |
| 101 | ) |
| 102 | asyncio.run(app.tencent_upload_note()) |
| 103 | |
| 104 | |
| 105 | if __name__ == "__main__": |
| 106 | upload_video_to_tencent() |
| 107 | # upload_video_to_tencent_scheduled() |
| 108 | # upload_note_to_tencent() |
| 109 | # upload_note_to_tencent_scheduled() |
| 110 |