Skip to content

Commit 5f09939

Browse files
committed
Added include_unavailable for get_items
1 parent 11924fc commit 5f09939

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

amazon_paapi/api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
from typing import List, Union
77
import time
88

9+
910
from . import models
1011
from .sdk.api.default_api import DefaultApi
1112
from .errors import InvalidArgumentException
1213
from .helpers import arguments
1314
from .helpers import requests
1415
from .helpers.generators import get_list_chunks
16+
from .helpers.items import get_items_including_unavailable
1517

1618

1719
class AmazonApi:
@@ -54,6 +56,7 @@ def get_items(
5456
merchant: models.Merchant = None,
5557
currency_of_preference: str = None,
5658
languages_of_preference: List[str] = None,
59+
include_unavailable: bool = False,
5760
**kwargs
5861
) -> List[models.Item]:
5962

@@ -70,6 +73,8 @@ def get_items(
7073
information should be returned. Expected currency code format is ISO 4217.
7174
languages_of_preference (``list[str]``, optional): Languages in order of preference in
7275
which the item information should be returned.
76+
include_unavailable (``bool``, optional): The returned list includes not available
77+
items. Not available items have the ASIN and item_info equals None. Defaults to False.
7378
kwargs (``dict``, optional): Any other arguments to be passed to the Amazon API.
7479
7580
Returns:
@@ -98,6 +103,9 @@ def get_items(
98103
items_response = requests.get_items_response(self, request)
99104
results.extend(items_response)
100105

106+
if include_unavailable:
107+
results = get_items_including_unavailable(results, items_ids)
108+
101109
return results
102110

103111

amazon_paapi/helpers/items.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""Module to manage items"""
2+
3+
from typing import List
4+
from .. import models
5+
6+
7+
def get_items_including_unavailable(items: List[models.Item], items_ids: List[str]) -> List[models.Item]:
8+
for index, asin in enumerate(items_ids):
9+
if items[index].asin != asin:
10+
items.insert(index, models.Item(asin=asin))
11+
return items

0 commit comments

Comments
 (0)