app: P2 migrations (year/seller_type/extras) + importer backfill, guards idempotent
- db.init_db gains guarded ALTER TABLE additions for listings.year / seller_type / extras (schema.sql v1 untouched; PRAGMA-checked idempotent) - rubric: extras_from_text() returns matched EXTRAS labels (table order) - importer: normalize computes year (existing helper), seller_type ONLY from a real state-item signal (dealer/private, else NULL), extras JSON; upsert rewrites the new columns on both paths - verified on live DB: import idempotent, counts stay 640/560/80, year backfilled on 599 rows, extras on 45, seller_type 0 (no state signal)
This commit is contained in:
@@ -146,6 +146,16 @@ def score_item(title, desc, price_num, km, year=None):
|
||||
return s, label
|
||||
|
||||
|
||||
def extras_from_text(title, desc):
|
||||
"""Return the labels of every EXTRAS pattern that matches title+desc.
|
||||
|
||||
One entry per label (labels are unique in the EXTRAS table); order is
|
||||
the table order. Stored on listings.extras at import (P2).
|
||||
"""
|
||||
text = (title + ' ' + desc).lower()
|
||||
return [label for pat, _pts, label in EXTRAS if re.search(pat, text)]
|
||||
|
||||
|
||||
def year_from_title(title):
|
||||
"""Extract a model year from the title, or None."""
|
||||
m = re.search(r'\b(19\d\d|20[0-2]\d)\b', title or '')
|
||||
|
||||
Reference in New Issue
Block a user