import json from pathlib import Path from sqlalchemy.orm import Session from app.models import Job from app.ral import hide_salary def seed_jobs(db: Session) -> int: path = Path(__file__).resolve().parent.parent / "seed_jobs.json" if not path.exists(): return 0 jobs = json.loads(path.read_text(encoding="utf-8")) created = 0 for item in jobs: exists = ( db.query(Job) .filter(Job.title == item["title"], Job.company == item["company"]) .first() ) if exists: continue description = item["description"] db.add( Job( title=item["title"], company=item["company"], subject=item.get("subject", "other"), location=item.get("location", ""), description=description, description_clean=hide_salary(description), extra_info=item.get("extra_info", ""), ral_min=item.get("ral_min"), ral_max=item.get("ral_max"), ral_exact=item.get("ral_exact"), work_type=item.get("work_type", "hybrid"), difficulty=item.get("difficulty", 1), status="ready", source="seed", ) ) created += 1 db.commit() return created