7455d7e426
130 issues auto-fixed (import ordering, UP045/UP006 type annotations), 33 issues manually fixed (E712/E501/E402/E722 + N818 rename + per-file wechat ignore for N8xx naming conventions). All 33 tests pass.
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
from fastapi import APIRouter
|
|
|
|
from app.api.deps import get_crawl_service
|
|
from app.models.schemas import CrawlTriggerRequest
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post("/crawl/trigger")
|
|
async def trigger_crawl(request: CrawlTriggerRequest):
|
|
service = get_crawl_service()
|
|
names = service.get_spider_names()
|
|
|
|
all_results = []
|
|
for name in names:
|
|
results = await service.run_spider(name)
|
|
all_results.extend(results)
|
|
|
|
return {
|
|
"spiders_run": names,
|
|
"total_announcements": sum(r.total_count for r in all_results),
|
|
"errors": [r.error_message for r in all_results if not r.success],
|
|
}
|
|
|
|
|
|
@router.get("/crawl/status")
|
|
async def crawl_status():
|
|
service = get_crawl_service()
|
|
return {
|
|
"spiders": service.get_spider_names(),
|
|
"running": False,
|
|
}
|
|
|
|
|
|
@router.get("/crawl/sources")
|
|
async def crawl_sources():
|
|
import json
|
|
|
|
from app.config import settings
|
|
sources = json.loads(settings.announcement_sources)
|
|
return {
|
|
"sources": [
|
|
{"code": code, "name": info["name"], "type": info["type"]}
|
|
for code, info in sources.items()
|
|
]
|
|
}
|