"""Parse outfit_recommendations JSON string from One Big Table into list[dict]."""
ifnottop_codes:returnproducts
forpinproducts:
try:
raw=p.get("outfit_recommendations")
conn=sqlite3.connect(SQLITE_DB_PATH)
ifrawandisinstance(raw,str):
conn.row_factory=sqlite3.Row
try:
cursor=conn.cursor()
p["outfit_recommendations"]=json.loads(raw)
placeholders=",".join(["?"]*len(top_codes))
except(json.JSONDecodeError,TypeError):
outfits=cursor.execute(f"SELECT * FROM pg__dashboard_canifa__ai_outfit_product_matches WHERE anchor_product_code IN ({placeholders})",top_codes).fetchall()