← العودة
Blog Post
عنوان المحادثة: عجبني كلامك أن معدل بال ai فعدلت
التاريخ: 07.11.2025
التصنيف: 🧠 الذكاء الاصطناعي وتعلم الآلة
إجمالي الرسائل: 5 | ياسر: 1 | M: 4
Yasser
عجبني كلامك أن معدل بال ai فعدلت
المحادثة الكاملة - 07.11.2025
M
بس محسنة بالai شكلها
07.11.2025 14:39
ياسر
عجبني كلامك أن معدل بال ai فعدلت
07.11.2025 14:44
M
قصدي بال ai
07.11.2025 14:45
M
if not variations: print(f"🔍 No variations from get_variations, trying search fallback...") info = main_item.get("item_info", {}) title = (info.get("title") or {}).get("display_value") or "" base_title = _norm_title(title) print(f"🔍 Search keywords: {base_title[:50]}") try: sr = self.api.search_items(keywords=base_title[:50], search_index="All", item_count=10) # التعامل مع list أو object search_items = None if isinstance(sr, list): search_items = sr elif hasattr(sr, 'items'): search_items = sr.items print(f"🔍 Search returned {len(search_items) if search_items else 0} items") for it in (search_items or []): d = _as_dict(it) item_asin = d.get("asin") item_parent = d.get("parent_asin") print(f"🔍 Found item: {item_asin}, parent: {item_parent}") # قبول المنتجات من نفس العائلة فقط if item_parent and item_parent == parent_asin: var_info = self._extract_variation_info(d, d.get("variation_attributes") or []) if var_info: variations.append(var_info) print(f"🔍 Added variation from search: {var_info.get('variant_name')}") except Exception as e: print(f"🔍 Search fallback error: {e}") pass print(f"🔍 Total variations found: {len(variations)}") # 4) filter and sort - نبقي كل الخيارات حتى بدون أسعار if len(variations) return {"success": True, "has_variations": False} variations.sort(key=lambda v: (-(v.get("savings_pct") or 0), (v.get("price_after_amount") or 1e9))) return { "success": True, "has_variations": True, "variations": variations, "variation_attributes": main_item.get("variation_attributes") or [], } except Exception as e: print("❌ variations error:", e) return {"success": False, "error": str(e)} def _extract_variation_info(self, item: Dict[str, Any], variation_attrs: List) -> Optional[Dict[str, Any]]: """استخراج معلومات variation من item""" try: asin = item.get("asin") if not asin: return None info = item.get("item_info", {}) title = (info.get("title") or {}).get("display_value") or "" # استخراج الأسعار prices = _extract_prices(item) # استخراج اللون والحجم من VariationAttributes color = None size = None storage = None # محاولة استخراج من variation_attributes if variation_attrs: for attr in variation_attrs: if isinstance(attr, dict): attr_name = (attr.get("name") or "").lower() attr_value = attr.get("value") # تجاهل القيم غير المفيدة مثل "Single", "One Size", إلخ if attr_value and attr_value.lower() in ["single", "one size", "default", "standard", "na", "n/a"]: continue if "color" in attr_name or "لون" in attr_name: color = attr_value elif "size" in attr_name or "حجم" in attr_name or "مقاس" in attr_name: size = attr_value elif "storage" in attr_name or "ذاكرة" in attr_name or "سعة" in attr_name:
07.11.2025 15:01
M
storage = attr_value # إذا لم نجد من attributes أو كانت القيم غير مفيدة، نحاول استخراج من العنوان if not color and not size and not storage: title_variants = _extract_model_variants(title) if title_variants.get("colors"): color = title_variants["colors"][0] if title_variants.get("sizes"): size = title_variants["sizes"][0] # محاولة أخيرة: استخراج من العنوان نفسه باستخدام patterns شائعة if not color and not size and not storage: # نبحث عن كلمات مثل: Lemon, Pink, Mild Care, Fresh, إلخ import re # نستخرج الكلمات بعد الفواصل أو الأقواس # مثال: "Lifebuoy Handwash - Lemon Fresh" -> "Lemon Fresh" # مثال: "Lifebuoy (Mild Care)" -> "Mild Care" # Pattern 1: بعد الشرطة dash_match = re.search(r'-\s*([A-Z][a-zA-Z\s]+?)(?:\s*-|\s*,|\s*\(|$)', title) if dash_match: variant_text = dash_match.group(1).strip() # تجنب الكلمات العامة if variant_text.lower() not in ["single", "pack", "handwash", "hand wash", "soap"]: color = variant_text # Pattern 2: داخل الأقواس if not color: paren_match = re.search(r'\(([A-Z][a-zA-Z\s]+?)\)', title) if paren_match: variant_text = paren_match.group(1).strip() if variant_text.lower() not in ["single", "pack"]: color = variant_text # Pattern 3: بعد الفاصلة if not color: comma_match = re.search(r',\s*([A-Z][a-zA-Z\s]+?)(?:\s*,|\s*-|$)', title) if comma_match: variant_text = comma_match.group(1).strip() if variant_text.lower() not in ["single", "pack"]: color = variant_text # استخراج ذكي من العنوان: نبحث عن الكلمات المميزة # مثل: "Lifebuoy Hand Wash Mild Care 200Ml" -> نستخرج "Mild Care" if not color: import re # نزيل اسم البراند والكلمات الشائعة title_clean = title # نزيل الـ brand names الشائعة أولاً title_clean = re.sub(r'\b(lifebuoy|dove|nivea|palmolive|dettol|lux)\b', '', title_clean, flags=re.IGNORECASE) title_clean = re.sub(r'\b(hand wash|handwash|soap|liquid|antibacterial|for|with|and|the)\b', '', title_clean, flags=re.IGNORECASE) # نبحث عن مجموعات كلمات بحروف كبيرة متتالية (مثل Lemon Fresh, Mild Care) variant_match = re.search(r'\b([A-Z][a-z]+(?:\s+[A-Z][a-z]+)*)\b(?=.*\d)', title_clean) if variant_match: potential_variant = variant_match.group(1).strip() # نتأكد إنها مش كلمات عامة common_words = ['pack', 'total', 'stronger', 'germ', 'protection', 'ml', 'percent'] if potential_variant.lower() not in common_words and len(potential_variant) > 3: color = potential_variant # بناء اسم مختصر للـ variation - نجمع كل الـ attributes variant_parts = [] if color: variant_parts.append(color) if size: variant_parts.append(size) if storage: variant_parts.append(storage) variant_name = " - ".join(variant_parts) if variant_parts else "الخيار الافتراضي" return { "asin": asin, "title": title, "variant_name": variant_name, # سيتم ترجمته في build_variations_message "color": color, "size": size, "storage": storage,
07.11.2025 15:01
← العودة إلى الرئيسية