GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — DevBlogKit/run.py at main · lihanyu1715446406-afk/DevBlogKit

Expand file tree

/

run.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
257 lines (220 loc) · 7.31 KB
/

run.py

Copy path

File metadata and controls

257 lines (220 loc) · 7.31 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/usr/bin/env python3
"""
博客自动生产流水线 — 命令行入口
实际的编排逻辑在 src/pipeline.py。这里只负责把命令行参数转成调用,
并把进度事件渲染成终端文案、把大纲确认接成 input()。
流程:材料读取 → 文章判型 → 大纲 →(可选确认)→ 正文 → 去 AI 味
→ 交付前自检(不合格回喂重写一次)→ 插图 → 封面提示词 → 组装输出
用法:
# 日常:输入题材,自动生成文章 + 插图 + 封面提示词
python run.py "Java 21 虚拟线程深入解析"
# 指定分类和标签
python run.py "xxx" --category "Java" --tags "Java, 并发, 性能"
# 带笔记或截图材料(自动判型为课程笔记文)
python run.py "RabbitMQ 入门" -m ./笔记.md -m ./截图目录
# 大纲先给你确认,确认后再写正文
python run.py "xxx" --review
# 跳过大纲阶段,直接生成(更快)
python run.py "xxx" --fast
# 跳过插图生成(纯文本 + 配图建议)
python run.py "xxx" --no-images
# 跳过「去 AI 味」改写
python run.py "xxx" --no-humanize
# 跳过交付前自检
python run.py "xxx" --no-selfcheck
# 跳过封面提示词生成
python run.py "xxx" --no-cover-prompt
"""
import argparse
import asyncio
import logging
import sys
from pathlib import Path
# 确保项目根目录在 Python path 中
sys.path.insert(0, str(Path(__file__).parent))
from src.config_loader import DEFAULT_LOG_LEVEL, load_config, validate_config
from src.pipeline import ProgressEvent, run_pipeline
logger = logging.getLogger("blog_pipeline")
def _banner(text: str):
print(f"\n{'=' * 50}")
print(f" {text}")
print(f"{'=' * 50}\n")
def _terminal_printer(event: ProgressEvent):
"""把进度事件渲染回原来的终端文案。"""
if event.banner:
_banner(event.message)
else:
print(event.message)
async def _ask_outline(outline: str) -> bool:
"""命令行的大纲确认。stdin 关闭时按「继续」处理,避免卡死。"""
try:
answer = input(" 继续写正文?[Y/n] ").strip().lower()
except EOFError:
answer = ""
return answer not in ("n", "no", "否")
async def run_pipeline_cli(
topic: str,
*,
category: str = None,
tags: list[str] = None,
output_dir: str = None,
fast: bool = False,
no_images: bool = False,
humanize: bool = True,
materials: list[str] = None,
article_type: str = "auto",
review: bool = False,
selfcheck: bool = True,
cover_prompt: bool = True,
):
"""命令行版本的流水线调用。
Returns:
成功时返回 index.md 路径;大纲被否时返回 None(与旧行为一致)
"""
result = await run_pipeline(
topic,
category=category,
tags=tags,
output_dir=output_dir,
fast=fast,
no_images=no_images,
humanize=humanize,
materials=materials,
article_type=article_type,
review=review,
selfcheck=selfcheck,
cover_prompt=cover_prompt,
on_progress=_terminal_printer,
confirm_outline=_ask_outline if review else None,
)
if result.get("cancelled"):
return None
return result.get("output_path")
def main():
parser = argparse.ArgumentParser(
description="博客自动生产流水线 — 输入题材(可选带笔记/截图),输出 Markdown 文章 + 插图",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
示例:
python run.py "Java 虚拟线程实战"
python run.py "MySQL 索引优化指南" --category "数据库" --tags "MySQL, 优化"
python run.py "RabbitMQ 入门" -m ./笔记.md -m ./截图目录 --review
""",
)
parser.add_argument(
"topic",
nargs="?",
help="文章题材(一句话或一段描述)",
)
parser.add_argument(
"--material",
"-m",
action="append",
default=None,
metavar="PATH",
help="笔记文件或截图目录,可重复传入",
)
parser.add_argument(
"--type",
default="auto",
choices=["auto", "knowledge", "course-note", "feature"],
help="文章类型(默认 auto:有材料按课程笔记文,无材料按知识点文)",
)
parser.add_argument(
"--review",
action="store_true",
help="先输出大纲等你确认,确认后再写正文",
)
parser.add_argument(
"--category",
default=None,
help="文章分类(如 Java、后端架构)",
)
parser.add_argument(
"--tags",
default=None,
help="文章标签,逗号分隔(如 'Java,并发')",
)
parser.add_argument(
"--output",
"-o",
default=None,
help="输出目录(默认自动生成: output/日期-标题/)",
)
parser.add_argument(
"--fast",
action="store_true",
help="跳过大纲阶段,直接生成文章(速度更快)",
)
parser.add_argument(
"--no-images",
action="store_true",
help="跳过插图生成,仅输出纯文本 + 配图建议",
)
parser.add_argument(
"--no-humanize",
action="store_true",
help="跳过去 AI 味改写,直接输出原始文章",
)
parser.add_argument(
"--no-selfcheck",
action="store_true",
help="跳过交付前自检",
)
parser.add_argument(
"--no-cover-prompt",
action="store_true",
help="跳过封面提示词生成(不做内容分析和风格选择)",
)
args = parser.parse_args()
# 初始化日志(命令行下保留控制台 + 文件双写)
try:
config = load_config()
log_config = config.get("logging", {})
from src.utils import setup_logging
setup_logging(
level=log_config.get("level", DEFAULT_LOG_LEVEL),
log_file=log_config.get("file"),
)
except FileNotFoundError:
from src.utils import setup_logging
setup_logging(DEFAULT_LOG_LEVEL)
# 检查配置
if args.topic:
try:
config = load_config()
warnings = validate_config(config)
if warnings:
print("\n⚠️ 配置提醒:")
for w in warnings:
print(f" - {w}")
print()
except FileNotFoundError:
pass
# 路由命令
if args.topic:
tags = None
if args.tags:
tags = [t.strip() for t in args.tags.split(",") if t.strip()]
asyncio.run(
run_pipeline_cli(
topic=args.topic,
category=args.category,
tags=tags,
output_dir=args.output,
fast=args.fast,
no_images=args.no_images,
humanize=not args.no_humanize,
materials=args.material,
article_type=args.type,
review=args.review,
selfcheck=not args.no_selfcheck,
cover_prompt=not args.no_cover_prompt,
)
)
else:
parser.print_help()
print("\n请提供文章题材,例如:")
print(' python run.py "Java 21 虚拟线程深入解析"')
if __name__ == "__main__":
main()
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.