Skip to content

Commit 4096b50

Browse files
committed
Added retries to sync call
1 parent 63e710d commit 4096b50

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
setup(
44
name = 'WIOpy',
55
packages = ['WIOpy'],
6-
version = '0.1.0',
6+
version = '0.1.1',
77
license='MIT',
88

99
description = 'Walmart IO API python wrapper',
1010

1111
author = 'CoderJosh',
1212
author_email = '[email protected]',
1313
url = 'https://github.com/CoderJoshDK/WIOpy',
14-
download_url = 'https://github.com/CoderJoshDK/WIOpy/archive/refs/tags/v_01.tar.gz',
14+
download_url = 'https://github.com/CoderJoshDK/WIOpy/archive/refs/tags/v_011.tar.gz',
1515
keywords = ['API', 'Wrapper', 'Python', 'Walmart', 'Affiliate', 'WalmartIO', 'Async', 'AIOHTTP'],
1616
install_requires=[
1717
'requests',

wiopy/WalmartIO.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def product_lookup(self, ids:Union[str, List[str]], **kwargs) -> List[WalmartPro
174174

175175
return products
176176

177-
def bulk_product_lookup(self, ids:Union[str, List[str]], amount:int=20, **kwargs):
177+
def bulk_product_lookup(self, ids:Union[str, List[str]], amount:int=20, retries:int=1, **kwargs):
178178
"""
179179
Walmart product lookup for a bulk of products. It will keep going even if there are errors
180180
This function is a generator that gives you #amount products at a time
@@ -208,12 +208,15 @@ def bulk_product_lookup(self, ids:Union[str, List[str]], amount:int=20, **kwargs
208208

209209
for idGroup in self._get_product_id_chunk(list(set(ids)), amount):
210210
params['ids'] = idGroup
211-
try:
212-
response = self._send_request(url, **params)
213-
yield [WalmartProduct(item) for item in response['items']]
214-
except InvalidRequestException as e:
215-
log.debug(f"bulk_product_lookup failed during the request with {idGroup} ids")
216-
log.debug(e)
211+
for attempt in range(retries):
212+
try:
213+
response = self._send_request(url, **params)
214+
yield [WalmartProduct(item) for item in response['items']]
215+
break
216+
except InvalidRequestException as e:
217+
if attempt == retries - 1:
218+
log.debug(f"bulk_product_lookup failed during the request with {idGroup} ids")
219+
log.debug(e)
217220

218221
def product_recommendation(self, itemId:str) -> List[WalmartProduct]:
219222
"""

0 commit comments

Comments
 (0)