chore: ruff 代码检查与修复
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.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from typing import Any, Dict, List
|
||||
from typing import Any
|
||||
|
||||
from app.crawler.base import PipelineConfig, PipelineResult
|
||||
from app.services.filter_service import dedup_by_hash
|
||||
|
||||
@@ -8,7 +9,7 @@ class PostCrawlPipeline:
|
||||
self.db = db_session
|
||||
self.notify = notification_service
|
||||
|
||||
async def process(self, announcements: List[Dict[str, Any]],
|
||||
async def process(self, announcements: list[dict[str, Any]],
|
||||
config: PipelineConfig) -> PipelineResult:
|
||||
result = PipelineResult()
|
||||
|
||||
@@ -47,8 +48,9 @@ class PostCrawlPipeline:
|
||||
|
||||
return result
|
||||
|
||||
async def _save_to_db(self, announcements: List[Dict[str, Any]]) -> int:
|
||||
async def _save_to_db(self, announcements: list[dict[str, Any]]) -> int:
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
|
||||
from app.models.announcement import Announcement
|
||||
|
||||
if not announcements:
|
||||
@@ -76,13 +78,14 @@ class PostCrawlPipeline:
|
||||
await self.db.commit()
|
||||
return result_proxy.rowcount if result_proxy.rowcount >= 0 else len(values)
|
||||
|
||||
async def _send_notifications(self, announcements: List[Dict[str, Any]]) -> int:
|
||||
async def _send_notifications(self, announcements: list[dict[str, Any]]) -> int:
|
||||
return await self.notify.send(announcements)
|
||||
|
||||
async def _mark_sent(self, announcements: List[Dict[str, Any]]) -> int:
|
||||
from app.models.announcement import Announcement
|
||||
async def _mark_sent(self, announcements: list[dict[str, Any]]) -> int:
|
||||
from sqlalchemy import update
|
||||
|
||||
from app.models.announcement import Announcement
|
||||
|
||||
hashes = [a["content_hash"] for a in announcements if a.get("content_hash")]
|
||||
if not hashes:
|
||||
return 0
|
||||
@@ -97,6 +100,6 @@ class PostCrawlPipeline:
|
||||
return result.rowcount
|
||||
|
||||
@staticmethod
|
||||
def _match_keywords(announcement: Dict[str, Any], keywords: List[str]) -> bool:
|
||||
def _match_keywords(announcement: dict[str, Any], keywords: list[str]) -> bool:
|
||||
text = f"{announcement.get('title', '')} {announcement.get('purchase_name', '')}"
|
||||
return any(kw in text for kw in keywords)
|
||||
|
||||
Reference in New Issue
Block a user