44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
"""
|
|
手动测试同步流程
|
|
"""
|
|
import asyncio
|
|
import sys
|
|
sys.path.insert(0, ".")
|
|
|
|
from app.database import AsyncSessionLocal, init_db
|
|
from app.models import Company
|
|
from app.services.cninfo_crawler import cninfo_service
|
|
from sqlalchemy import select
|
|
|
|
async def test_sync():
|
|
print("=" * 60)
|
|
print("手动测试同步流程")
|
|
print("=" * 60)
|
|
|
|
# 初始化数据库
|
|
await init_db()
|
|
|
|
async with AsyncSessionLocal() as db:
|
|
# 获取第一个公司
|
|
stmt = select(Company).where(Company.is_active == True).limit(1)
|
|
result = await db.execute(stmt)
|
|
company = result.scalar_one_or_none()
|
|
|
|
if not company:
|
|
print("❌ 没有找到任何公司,请先添加公司")
|
|
return
|
|
|
|
print(f"\n📊 测试同步: {company.stock_code} {company.short_name}")
|
|
print("-" * 40)
|
|
|
|
try:
|
|
new_count = await cninfo_service.sync_company_reports(db, company)
|
|
print(f"\n✅ 同步完成,新增 {new_count} 份报告")
|
|
except Exception as e:
|
|
print(f"\n❌ 同步失败: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(test_sync())
|