diff --git a/app/beauty_main.py b/app/beauty_main.py index b54aa0d..1d82c1e 100644 --- a/app/beauty_main.py +++ b/app/beauty_main.py @@ -153,12 +153,15 @@ async def enriched( prescreen_status: str = Query(None), niche: str = Query(None), site_type: str = Query(None), + keyword: str = Query(None), + tld: str = Query(None), page: int = Query(1, ge=1), limit: int = Query(100, ge=1, le=1000), ): total, rows = await get_enriched( min_score=min_score, country=country, prescreen_status=prescreen_status, niche=niche, site_type=site_type, + keyword=keyword, tld=tld, page=page, limit=limit, ) return {"page": page, "limit": limit, "total": total, "results": rows} diff --git a/app/db.py b/app/db.py index d91130c..89cc928 100644 --- a/app/db.py +++ b/app/db.py @@ -334,6 +334,7 @@ async def get_stats(): async def get_enriched(min_score=0, cms=None, country=None, kit_digital=None, ai_only=False, lead_quality=None, prescreen_status=None, niche=None, site_type=None, + keyword=None, tld=None, page=1, limit=100): offset = (page - 1) * limit conditions = ["score >= ?"] @@ -343,7 +344,7 @@ async def get_enriched(min_score=0, cms=None, country=None, kit_digital=None, params.append(cms) if country: conditions.append("ip_country = ?") - params.append(country) + params.append(country.upper()) if kit_digital is not None: conditions.append("kit_digital = ?") params.append(1 if kit_digital else 0) @@ -363,6 +364,14 @@ async def get_enriched(min_score=0, cms=None, country=None, kit_digital=None, if site_type: conditions.append("site_type = ?") params.append(site_type) + if keyword: + kw = f"%{keyword.lower()}%" + conditions.append("(LOWER(domain) LIKE ? OR LOWER(COALESCE(page_title,'')) LIKE ?)") + params.extend([kw, kw]) + if tld: + tld_clean = tld.lower().lstrip(".") + conditions.append("LOWER(domain) LIKE ?") + params.append(f"%.{tld_clean}") where = "WHERE " + " AND ".join(conditions) async with aiosqlite.connect(SQLITE_PATH, timeout=30) as db: db.row_factory = aiosqlite.Row diff --git a/app/static/beauty/index.html b/app/static/beauty/index.html index 95b5484..196ef5a 100644 --- a/app/static/beauty/index.html +++ b/app/static/beauty/index.html @@ -6,19 +6,10 @@