feat: ozon sync
This commit is contained in:
@@ -4,34 +4,18 @@ from collections import defaultdict
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
from external.marketplace.base.product_synchronizer import BaseProductSynchronizer
|
||||
from external.marketplace.wildberries.core import WildberriesMarketplaceApi
|
||||
from marketplaces.base.core import BaseMarketplaceController
|
||||
from models import Product, ProductBarcode, ProductImage, WildberriesProduct
|
||||
|
||||
|
||||
class WildberriesProductSynchronizer:
|
||||
products: list[Product]
|
||||
barcodes: list[ProductBarcode]
|
||||
images: list[ProductImage]
|
||||
wildberries_products: list[WildberriesProduct]
|
||||
|
||||
def __init__(self, session, marketplace, api):
|
||||
self.session = session
|
||||
self.marketplace = marketplace
|
||||
self.api = api
|
||||
self.products = []
|
||||
self.barcodes = []
|
||||
self.images = []
|
||||
self.wildberries_products = []
|
||||
|
||||
def _clear(self):
|
||||
self.products = []
|
||||
self.barcodes = []
|
||||
self.images = []
|
||||
self.wildberries_products = []
|
||||
class WildberriesProductSynchronizer(BaseProductSynchronizer):
|
||||
marketplace_products: list[WildberriesProduct]
|
||||
api: WildberriesMarketplaceApi
|
||||
|
||||
async def _write(self):
|
||||
instances = self.products + self.wildberries_products + self.barcodes + self.images
|
||||
instances = self.products + self.marketplace_products + self.barcodes + self.images
|
||||
start = time.time()
|
||||
self.session.add_all(instances)
|
||||
await self.session.commit()
|
||||
@@ -125,7 +109,7 @@ class WildberriesProductSynchronizer:
|
||||
self.products.append(product)
|
||||
self.barcodes.extend(barcodes)
|
||||
self.images.extend(images)
|
||||
self.wildberries_products.append(wildberries_product)
|
||||
self.marketplace_products.append(wildberries_product)
|
||||
|
||||
async def create_products(self):
|
||||
self._clear()
|
||||
|
||||
Reference in New Issue
Block a user