-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsimple_test.py
More file actions
87 lines (70 loc) · 2.81 KB
/
simple_test.py
File metadata and controls
87 lines (70 loc) · 2.81 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
#!/usr/bin/env python3
"""
简单测试 - 不限制时间,确保能抓到论文
"""
import sys
from pathlib import Path
# 添加项目根目录到路径
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
from scripts.fetch_papers import PaperFetcher
from scripts.generate_html import HTMLGenerator
def simple_test():
"""简单测试 - 无时间限制"""
print("🧪 简单测试开始(无时间限制)...")
print("=" * 60)
# 创建抓取器
fetcher = PaperFetcher()
# 修改配置:只抓取一个类别,不限制时间
fetcher.config['sources']['arxiv']['categories'] = ['cs.AI']
fetcher.config['sources']['arxiv']['max_results'] = 10
fetcher.config['sources']['arxiv']['days_back'] = 365 # 1年内的论文都可以
print("📥 正在抓取 cs.AI 类别的 10 篇最新论文(不限制时间)...")
print()
try:
papers = fetcher.fetch_arxiv_papers()
if papers:
print(f"✅ 成功抓取 {len(papers)} 篇论文!")
print()
# 显示前3篇
for i, paper in enumerate(papers[:3], 1):
print(f"📄 论文 {i}:")
print(f" 标题: {paper['title'][:80]}...")
print(f" 作者: {', '.join(paper['authors'][:2])} {'等' if len(paper['authors']) > 2 else ''}")
print(f" 发布: {paper['published']} | 更新: {paper['updated']}")
print(f" 标签: {', '.join(paper['tags']) if paper['tags'] else '未分类'}")
print()
# 保存数据
print("💾 保存数据...")
fetcher.save_papers(papers)
print("✅ 数据已保存到 data/papers.json")
print()
# 生成网页
print("🌐 生成网页...")
generator = HTMLGenerator()
generator.run()
print()
print("=" * 60)
print("✨ 测试完全成功!")
print()
print("📝 下一步:")
print(" 1. 在浏览器中打开: docs\\index.html")
print(" 2. 如果效果满意,可以修改 config.yaml 中的 days_back")
print(" 3. 运行完整抓取: python scripts\\fetch_papers.py")
print()
return 0
else:
print("❌ 仍然未能抓取到论文")
print()
print("请检查:")
print(" 1. 网络连接是否正常")
print(" 2. 能否访问 https://arxiv.org")
print()
return 1
except Exception as e:
print(f"❌ 发生错误: {e}")
import traceback
traceback.print_exc()
return 1
if __name__ == "__main__":
sys.exit(simple_test())