Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
127 lines (110 loc) · 4.01 KB
/
Copy pathsetup.py
File metadata and controls
127 lines (110 loc) · 4.01 KB
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
#!/usr/bin/env python3
"""
AtomBrief 初始化脚本
一键配置所有必需文件和目录
"""
import os
import sys
from pathlib import Path
import shutil
def main():
print("🚀 AtomBrief 初始化\n")
print("=" * 60)
base_dir = Path(__file__).parent
# Step 1: 创建目录
print("\n1️⃣ 创建必需目录...")
dirs = [
base_dir / "data",
base_dir / "logs",
base_dir / "web" / "templates",
base_dir / "web" / "static",
]
for d in dirs:
d.mkdir(parents=True, exist_ok=True)
print(f" ✓ {d.relative_to(base_dir)}")
# Step 2: 创建 .env(如果不存在)
print("\n2️⃣ 配置环境变量...")
env_file = base_dir / ".env"
env_example = base_dir / ".env.example"
if not env_file.exists() and env_example.exists():
shutil.copy(env_example, env_file)
print(f" ✓ 已创建 .env(从 .env.example)")
print(f" ⚠️ 请编辑 .env 并填入真实密钥:")
print(f" - DEEPSEEK_API_KEY")
print(f" - GITHUB_TOKEN")
elif env_file.exists():
print(f" ✓ .env 已存在")
else:
print(f" ⚠️ .env.example 不存在,无法自动生成")
# Step 3: 创建 .gitkeep
print("\n3️⃣ 初始化 Git 追踪...")
for d in ["data", "logs"]:
gitkeep = base_dir / d / ".gitkeep"
if not gitkeep.exists():
gitkeep.touch()
print(f" ✓ {d}/.gitkeep")
# Step 4: 创建示例数据
print("\n4️⃣ 创建示例文件...")
sample_opml = base_dir / "data" / "readyou.opml"
if not sample_opml.exists():
sample_opml.write_text("""<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0">
<head>
<title>AtomBrief RSS Subscriptions</title>
<dateCreated>2026-06-29T00:00:00Z</dateCreated>
</head>
<body>
<outline text="Tech News" title="Tech News">
<outline type="rss" text="Hacker News" title="Hacker News" xmlUrl="https://news.ycombinator.com/rss"/>
<outline type="rss" text="MIT Technology Review" title="MIT Technology Review" xmlUrl="https://www.technologyreview.com/feed.xml"/>
</outline>
<outline text="Science" title="Science">
<outline type="rss" text="Nature" title="Nature" xmlUrl="https://www.nature.com/nature.rss"/>
</outline>
</body>
</opml>
""", encoding="utf-8")
print(f" ✓ data/readyou.opml (示例)")
else:
print(f" ⊘ data/readyou.opml 已存在")
# Step 5: 检查虚拟环境
print("\n5️⃣ 检查虚拟环境...")
venv_dir = base_dir / "venv"
if venv_dir.exists():
print(f" ✓ venv 已存在")
else:
print(f" ⚠️ venv 不存在")
print(f" 运行: python -m venv venv")
print(f" 然后: venv\\Scripts\\activate (Windows) 或 source venv/bin/activate (Mac/Linux)")
print(f" 最后: pip install -r requirements.txt")
# Step 6: 验证配置
print("\n6️⃣ 验证配置...")
try:
from src.config import validate_config
errors = validate_config()
if errors:
print(f" ⚠️ 配置警告:")
for err in errors:
print(f" {err}")
else:
print(f" ✅ 所有关键配置已准备")
except Exception as e:
print(f" ⚠️ 验证失败(可能还未安装依赖): {e}")
print("\n" + "=" * 60)
print("\n✅ 初始化完成!\n")
print("📚 下一步:")
print(" 1. 编辑 .env 填入你的 API 密钥")
print(" 2. 在 ReadYou 中导出 OPML 订阅源")
print(" 3. 运行: python main.py config-check")
print(" 4. 运行: python main.py daily (测试晚报生成)")
print(" 5. 运行: python main.py serve (打开 Web UI)")
print("\n📖 详见 DEPLOYMENT.md")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\n\n⏸️ 已中止")
sys.exit(1)
except Exception as e:
print(f"\n❌ 错误: {e}")
sys.exit(1)