v1.0
This commit is contained in:
@@ -14,9 +14,11 @@ class OzonMarketplaceApi(BaseMarketplaceApi):
|
||||
def __init__(self, marketplace: Marketplace):
|
||||
self.marketplace = marketplace
|
||||
auth_data = json.loads(marketplace.auth_data)
|
||||
client_id = auth_data.get('clientId')
|
||||
|
||||
self.limiter_key = str(marketplace.company_id) + str(client_id)
|
||||
self.headers = {
|
||||
'Client-Id': auth_data.get('clientId'),
|
||||
'Client-Id': client_id,
|
||||
'Api-Key': auth_data.get('clientToken')
|
||||
}
|
||||
|
||||
@@ -32,14 +34,13 @@ class OzonMarketplaceApi(BaseMarketplaceApi):
|
||||
return
|
||||
max_stocks = 100
|
||||
chunks = utils.chunk_list(data, max_stocks)
|
||||
limiter = BatchLimiter(max_requests=80, period=60)
|
||||
limiter = BatchLimiter()
|
||||
|
||||
async def send_stock_chunk(chunk):
|
||||
try:
|
||||
await limiter.acquire()
|
||||
await limiter.acquire_ozon(self.limiter_key)
|
||||
request_data = {'stocks': chunk}
|
||||
response = await self._method('POST', '/v2/products/stocks', data=request_data)
|
||||
print(request_data)
|
||||
response = await response.json()
|
||||
error_message = response.get('message')
|
||||
error_code = response.get('code')
|
||||
@@ -48,7 +49,7 @@ class OzonMarketplaceApi(BaseMarketplaceApi):
|
||||
f'Error occurred when sending stocks to [{self.marketplace.id}]: {error_message} ({error_code})')
|
||||
except Exception as e:
|
||||
logging.error(
|
||||
f'Exception occurred while sending stocks to marketplace ID [{self.marketplace.id}]: {str(e)}')
|
||||
f'Exception occurred while sending stocks to marketplace ID [{self.marketplace.id}]: {str(e)}')
|
||||
|
||||
tasks = [send_stock_chunk(chunk) for chunk in chunks]
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
Reference in New Issue
Block a user