feat: ozon sync
This commit is contained in:
		
							
								
								
									
										40
									
								
								external/marketplace/base/product_synchronizer.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								external/marketplace/base/product_synchronizer.py
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
from abc import ABC, abstractmethod
 | 
			
		||||
 | 
			
		||||
from sqlalchemy.ext.asyncio import AsyncSession
 | 
			
		||||
 | 
			
		||||
from external.marketplace.base import BaseMarketplaceApi
 | 
			
		||||
from models import Product, ProductBarcode, ProductImage
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BaseProductSynchronizer(ABC):
 | 
			
		||||
    products: list[Product] = []
 | 
			
		||||
    barcodes: list[ProductBarcode] = []
 | 
			
		||||
    images: list[ProductImage] = []
 | 
			
		||||
    marketplace_products: list = []
 | 
			
		||||
    api: BaseMarketplaceApi
 | 
			
		||||
    session: AsyncSession
 | 
			
		||||
 | 
			
		||||
    def __init__(self, session, marketplace, api):
 | 
			
		||||
        self.session = session
 | 
			
		||||
        self.marketplace = marketplace
 | 
			
		||||
        self.api = api
 | 
			
		||||
        self._clear()
 | 
			
		||||
 | 
			
		||||
    def _clear(self):
 | 
			
		||||
        self.products = []
 | 
			
		||||
        self.barcodes = []
 | 
			
		||||
        self.images = []
 | 
			
		||||
        self.marketplace_products = []
 | 
			
		||||
 | 
			
		||||
    async def _write(self):
 | 
			
		||||
        instances = self.products + self.marketplace_products + self.barcodes + self.images
 | 
			
		||||
        self.session.add_all(instances)
 | 
			
		||||
        await self.session.commit()
 | 
			
		||||
 | 
			
		||||
    @abstractmethod
 | 
			
		||||
    async def create_products(self):
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
    @abstractmethod
 | 
			
		||||
    async def synchronize_products(self):
 | 
			
		||||
        pass
 | 
			
		||||
		Reference in New Issue
	
	Block a user