astock-agent/backend/scripts/cleanup_recommendations.py
2026-04-16 16:40:56 +08:00

34 lines
792 B
Python

"""删除评分低于 60 的推荐记录
用法: python -m scripts.cleanup_recommendations
"""
import asyncio
from sqlalchemy import text
from app.db.database import get_db
async def cleanup():
async with get_db() as db:
# 先统计
result = await db.execute(
text("SELECT COUNT(*) FROM recommendations WHERE score < 60")
)
count = result.scalar()
print(f"找到 {count} 条评分低于 60 的推荐记录")
if count == 0:
print("无需清理")
return
# 删除
await db.execute(
text("DELETE FROM recommendations WHERE score < 60")
)
await db.commit()
print(f"已删除 {count} 条记录")
if __name__ == "__main__":
asyncio.run(cleanup())