feat: v1.7 overhaul - identity hash, triple wallet, financial ledger, and security audit system
This commit is contained in:
61
backend/app/workers/brand_seeder.py
Normal file
61
backend/app/workers/brand_seeder.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import asyncio
|
||||
import httpx
|
||||
import logging
|
||||
from sqlalchemy import text
|
||||
from app.db.session import SessionLocal
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger("Smart-Seeder-v1.0.2")
|
||||
|
||||
async def seed_with_priority():
|
||||
# RDW lekérdezés: Márka, Fő kategória és darabszám
|
||||
# Olyan márkákat keresünk, amikből legalább 10 db van
|
||||
URL = "https://opendata.rdw.nl/resource/m9d7-ebf2.json?$select=merk,voertuigsoort,count(*)%20as%20total&$group=merk,voertuigsoort&$having=total%20>=%2010"
|
||||
|
||||
logger.info("📥 Adatok lekérése az RDW-től prioritásos besoroláshoz...")
|
||||
|
||||
async with httpx.AsyncClient(timeout=120) as client:
|
||||
try:
|
||||
resp = await client.get(URL)
|
||||
if resp.status_code != 200:
|
||||
logger.error(f"❌ API hiba: {resp.status_code}")
|
||||
return
|
||||
|
||||
raw_data = resp.json()
|
||||
async with SessionLocal() as db:
|
||||
for entry in raw_data:
|
||||
make = entry.get("merk", "").upper()
|
||||
v_kind = entry.get("voertuigsoort", "")
|
||||
|
||||
# --- PRIORITÁS LOGIKA ---
|
||||
# 1. Személyautó (Personenauto) -> 'pending' (Azonnali feldolgozás)
|
||||
# 2. Motor (Motorfiets) -> 'queued_motor'
|
||||
# 3. Minden más -> 'queued_heavy'
|
||||
|
||||
status = 'queued_heavy'
|
||||
if "Personenauto" in v_kind:
|
||||
status = 'pending'
|
||||
elif "Motorfiets" in v_kind:
|
||||
status = 'queued_motor'
|
||||
|
||||
query = text("""
|
||||
INSERT INTO data.catalog_discovery (make, model, vehicle_class, source, status)
|
||||
VALUES (:make, 'ALL_VARIANTS', :v_class, 'smart_seeder_v2_1', :status)
|
||||
ON CONFLICT (make, model, vehicle_class) DO UPDATE
|
||||
SET status = EXCLUDED.status WHERE data.catalog_discovery.status = 'pending';
|
||||
""")
|
||||
|
||||
await db.execute(query, {
|
||||
"make": make,
|
||||
"v_class": v_kind,
|
||||
"status": status
|
||||
})
|
||||
|
||||
await db.commit()
|
||||
logger.info("✅ A Discovery lista feltöltve és prioritizálva (Autók az élen)!")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"❌ Hiba: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(seed_with_priority())
|
||||
Reference in New Issue
Block a user