83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
"""写入专项估价指南样例(四类各至少一条)。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
|
|
def main() -> int:
|
|
try:
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
except ImportError:
|
|
pass
|
|
|
|
from app.core.config import get_settings
|
|
from app.db import Base, SessionLocal, get_engine
|
|
from app.models.home import create_article
|
|
|
|
settings = get_settings()
|
|
if not settings.database_url.strip():
|
|
print("DATABASE_URL 为空", file=sys.stderr)
|
|
return 1
|
|
|
|
import app.models.expert # noqa: F401
|
|
import app.models.home # noqa: F401
|
|
import app.models.member # noqa: F401
|
|
|
|
engine = get_engine()
|
|
Base.metadata.create_all(bind=engine)
|
|
SessionLocal.configure(bind=engine)
|
|
db = SessionLocal()
|
|
samples = [
|
|
("residential", "住宅估价业务指引", "<p>住宅估价受理、查勘、比较法选用与报告出具要点。</p>"),
|
|
("commercial", "商业地产估价流程指引", "<p>收益法参数、租约核查与市场调查注意事项。</p>"),
|
|
("industrial", "工业房地产估价指引", "<p>工业用途、构筑物与设备附着物边界说明。</p>"),
|
|
("specialty", "特色地产(文旅/养老)估价指引", "<p>特色业态可比案例稀缺时的路径与披露要求。</p>"),
|
|
]
|
|
try:
|
|
from sqlalchemy import select
|
|
from app.models.home import HomeArticle, HomeArticleKind
|
|
|
|
existing = {
|
|
row.kind
|
|
for row in db.scalars(
|
|
select(HomeArticleKind).where(
|
|
HomeArticleKind.article_id.in_(
|
|
select(HomeArticle.id).where(HomeArticle.category == "appraisal_guides")
|
|
)
|
|
)
|
|
).all()
|
|
}
|
|
created = 0
|
|
for kind, title, html in samples:
|
|
if kind in existing:
|
|
continue
|
|
create_article(
|
|
db,
|
|
{
|
|
"category": "appraisal_guides",
|
|
"kind": kind,
|
|
"title": title,
|
|
"publishedAt": "2025-09-01T08:00:00",
|
|
"published": True,
|
|
"bodyHtml": html,
|
|
"attachmentFileIds": [],
|
|
},
|
|
)
|
|
created += 1
|
|
print(f"appraisal_guides seeded: +{created}")
|
|
return 0
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|