-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-fetch.py
More file actions
54 lines (39 loc) · 1.42 KB
/
Copy pathtest-fetch.py
File metadata and controls
54 lines (39 loc) · 1.42 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
"""测试数据源获取功能"""
import asyncio
import logging
import fetcher # noqa: F401 自动注册所有源
from fetcher.registry import FetcherRegistry
from logger.logging import setup_logger
from storage.cache import CacheStorage
setup_logger()
logger = logging.getLogger(__name__)
async def fetch_source(source_id: str):
"""获取单个源的数据"""
fetcher_instance = FetcherRegistry.get(source_id)
logger.info(f"开始获取 {source_id}...")
try:
items = await fetcher_instance.fetch()
logger.info(f"获取到 {len(items)} 条数据")
for i, item in enumerate(items[:5], 1):
logger.info(f" {i}. {item.title}")
if item.description:
logger.info(f" {item.description[:50]}...")
storage = CacheStorage()
storage.save(source_id, items
logger.info(f"✅ {source_id} - 成功")
return True
except Exception as e:
logger.error(f"❌ {source_id} - 失败: {e}")
import traceback
traceback.print_exc()
return False
async def main():
"""测试获取数据源"""
source_ids = ["baidu", "toutiao", "ifeng", "cailian", "wallstreetcn", "jin10"]
logger.info(f"测试源: {', '.join(source_ids)}")
logger.info("=" * 50)
for source_id in source_ids:
await fetch_source(source_id)
logger.info("-" * 50)
if __name__ == "__main__":
asyncio.run(main())