import json
import sqlite3

c = sqlite3.connect('database/canifa_ai_dump.sqlite')
c.row_factory = sqlite3.Row
try:
    rows = c.execute("SELECT magento_ref_code, product_name, product_line_vn FROM sr__test_db__magento_product_dimension_with_text_embedding WHERE product_line_vn LIKE '%lót%' OR product_name LIKE '%sịp%' OR product_name LIKE '%boxer%' OR product_name LIKE '%tam giác%'").fetchall()
    
    out = []
    for r in rows:
        if r['product_line_vn'] not in ['Áo lót']:
            out.append(dict(r))
            
    with open("out3.txt", "w", encoding="utf-8") as f:
        f.write(f"Found {len(out)} products\n")
        for o in out:
            f.write(json.dumps(o, ensure_ascii=False) + "\n")
except Exception as e:
    print(f"Error: {e}")
