Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two method to get list of UPC and EAN #117

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions amazon/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,22 @@ def ean(self):
ean = self._safe_get_element_text(
'EANListElement', root=ean_list[0])
return ean

@property
def eans(self):
"""EANs.

:return:
EANs ([string])
"""

ean_list = self._safe_get_element('ItemAttributes.EANList.EANListElement')
if ean_list and len(ean_list) > 0:
eans = [ean.text for ean in ean_list]
else:
eans = []

return eans

@property
def upc(self):
Expand All @@ -996,6 +1012,22 @@ def upc(self):
upc = self._safe_get_element_text(
'UPCListElement', root=upc_list[0])
return upc

@property
def upcs(self):
"""UPCs.

:return:
UPCs ([string])
"""

upc_list = self._safe_get_element('ItemAttributes.UPCList.UPCListElement')
if upc_list and len(upc_list) > 0:
upcs = [upc.text for upc in upc_list]
else:
upcs = []

return upcs

@property
def color(self):
Expand Down
2 changes: 2 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def test_lookup(self):
product = self.amazon.lookup(ItemId="B00ZV9PXP2")
assert_true('Kindle' in product.title)
assert_equals(product.ean, '0848719083774')
assert_true(len(product.eans) > 0)
assert_true(len(product.upcs) >= 0)
assert_equals(
product.large_image_url,
'https://images-na.ssl-images-amazon.com/images/I/51hrdzXLUHL.jpg'
Expand Down