Skip to content

Instantly share code, notes, and snippets.

@thanhpd-teko
Created April 16, 2019 04:02
Show Gist options
  • Save thanhpd-teko/63d50bf2d240d1a7a9c1305d57c18351 to your computer and use it in GitHub Desktop.
Save thanhpd-teko/63d50bf2d240d1a7a9c1305d57c18351 to your computer and use it in GitHub Desktop.
product listing integeration

Listing library

Listing library is a Python library for index product data from catalog, ppm, warehouse, sell, rating to elastic search

Installation

Use the package manager pip to install listing-lib.

pip install git+git+https://[email protected]/teko-vn/es-updater.git

Usage

For Catalog

from listinglib.esconfig import EsMode
from listinglib.service.catalog_updater import CatalogUpdater
from listinglib.models.catalog import CatalogProduct

# Khoi tao moi truong
catalog_updater = CatalogUpdater(EsMode.DEV)

# Tao model
product = CatalogProduct()
product1 = CatalogProduct()
product2 = CatalogProduct()

# Save single product data
catalog_updater.save(product)

# Save multi product data
products = [product, product1, product2]
catalog_updater.save_all(products)

For PPM

from listinglib.esconfig import EsMode
from listinglib.service.ppm_updater import PpmUpdater
from listinglib.models.ppm import PpmProduct

# Khoi tao moi truong
ppm_updater = PpmUpdater(EsMode.DEV)

# Tao model
product = PpmProduct()
product1 = PpmProduct()
product2 = PpmProduct()

# Save single product data
ppm_updater.save(product)

# Save multi product data
products = [product, product1, product2]
ppm_updater.save_all(products)

Các nguồn dữ liệu khác hoạt động tương tự với bộ updater riêng cùng với model riêng

For Catalog

from listinglib.esconfig import EsMode
from listinglib.service import EsUpdater

# Khoi tao moi truong
EsUpdater.set_mode(EsMode.DEV)

@catalog_updater
def func1():
    product = {
                  "sku": "18110261",
                  "name": "Máy tính xách tay/ Laptop Dell Vostro 5568-70169219 (I5-7200U) (Xám)",
                  "seller_id": 2,
                  "url": "https://phongvu.vn/pin-dung-cho-laptop-asus-a32-x450.html",
                  "images": [
                    {
                      "url": "https://phongvu.vn/media/catalog/product/cache/23/small_image/60x60/9df78eab33525d08d6e5fb8d27136e95//d/e/dell_vostro_5568_1.jpg",
                      "priority": 1,
                      "label": ""
                    },
                    {
                      "url": "https://phongvu.vn/media/catalog/product/cache/23/small_image/60x60/9df78eab33525d08d6e5fb8d27136e95//d/e/dell_vostro_5568_1.jpg",
                      "priority": 2,
                      "label": ""
                    }
                  ],
                  "display_name": "Laptop Dell Vostro 5568-70169219 (15.6\"/i5-7200U 2.5 GHz - 3.1 GHz/4GB RAM/1TB HDD/Intel HD Graphics 620/Ubuntu/2kg)",
                  "color": {
                    "code": "RED",
                    "name": "Đỏ"
                  },
                  "attributes": [
                    {
                      "id": 1,
                      "code": "KT",
                      "name": "Kích thước",
                      "priority": 1,
                      "is_searchable": True,
                      "is_filterable": True,
                      "value": "43 inch",
                      "is_comparable": True
                    },
                    {
                      "id": 2,
                      "code": "CL",
                      "name": "Màu sắc",
                      "priority": 2,
                      "is_searchable": True,
                      "is_filterable": True,
                      "value": "Vàng",
                      "is_comparable": True
                    }
                  ],
                  "categories": [
                    {
                      "id": 1,
                      "code": "1",
                      "name": "Văn phòng, mạng, an ninh",
                      "level": "1",
                      "parent_id": None
                    },
                    {
                      "id": 2,
                      "code": "2",
                      "name": "Thiết bị An ninh",
                      "level": "2",
                      "parent_id": 1
                    },
                    {
                      "id": 3,
                      "code": "3",
                      "name": "Đầu ghi KTS",
                      "level": "3",
                      "parent_id": 2
                    },
                    {
                      "id": 4,
                      "code": "4",
                      "name": "Đầu thu KBS",
                      "level": "4",
                      "parent_id": 3
                    }
                  ],
                  "brand": {
                    "id": 1,
                    "code": "SS",
                    "name": "Samsung",
                    "description": "abc"
                  },
                  "status": {
                    "selling_status": {
                      "code": "ACTIVE",
                      "name": "WTF"
                    },
                    "editing_status": {
                      "code": "ACTIVE",
                      "name": "WTF"
                    }
                  },
                  "seo_info": {
                    "meta_keyword": "aaa",
                    "short_description": "aa",
                    "description": "aa",
                    "meta_title": "aa",
                    "meta_description": "aa"
                  },
                  "warranty": {
                    "months": 12,
                    "description": ""
                  },
                  "created_at": "2019-01-02T10:00:00Z",
                  "product_group": {
                    "id": 3,
                    "name": "Laptop abc",
                    "variation_attributes": [
                      {
                        "id": 1,
                        "code": "KT",
                        "name": "Kích thước"
                      },
                      {
                        "id": 2,
                        "code": "DL",
                        "name": "Dung lượng"
                      }
                    ],
                    "variation_products": [
                      {
                        "sku": "1703341",
                        "attribute_values": [
                          {
                            "id": 1,
                            "code": "KT",
                            "value": "43 inch"
                          },
                          {
                            "id": 2,
                            "code": "DL",
                            "value": "32G"
                          }
                        ]
                      }
                    ]
                  },
                  "supplier_sale_price": 5000000,
                  "attribute_groups": [
                    {
                      "id": 3,
                      "name": "Ứng dụng giải trí",
                      "group_value": "Youtube, Netflix, Trình duyệt web",
                      "priority": 1,
                      "parent_id": 5,
                      "highlight": True
                    },
                    {
                      "id": 5,
                      "name": "Ứng dụng",
                      "group_value": "",
                      "priority": 1,
                      "parent_id": None,
                      "highlight": False
                    }
                  ],
                  "tags": [
                    "new",
                    "highlight",
                    "hot"
                  ]
                }
    # Ham tra ve du lieu json can insert vao elastic search
    return product

@catalog_updater
def func2():
    products = [...]
    # Ham tra ve list du lieu json can insert vao elastic search
    return products

# Du lieu tra ra cua func1 se duoc validate va index vao ES
func1()
# Du lieu tra ra cua func2 se duoc validate va index vao ES
func2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment