Skip to content

Commit

Permalink
Added ability to retrieve the list of images from a product
Browse files Browse the repository at this point in the history
  • Loading branch information
caroso1222 committed Sep 16, 2016
1 parent be4dbc9 commit a8e8972
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -2,12 +2,12 @@
setup(
name = 'wapy',
packages = ['wapy'],
version = '0.0.4',
version = '0.1.0',
description = 'A python wrapper for the Walmart Open API',
author = 'Carlos Roso',
author_email = 'ce.roso398@gmail.com',
url = 'https://github.com/caroso1222/wapy',
download_url = 'https://github.com/caroso1222/wapy/tarball/0.0.4',
download_url = 'https://github.com/caroso1222/wapy/tarball/0.1.0',
keywords = ['walmart', 'wrapper', 'walmart api', 'api', 'python client', 'python'],
install_requires=["requests"],
classifiers=[
Expand Down
37 changes: 37 additions & 0 deletions wapy/api.py
Expand Up @@ -452,6 +452,16 @@ def large_image(self):
"""
return self.response_handler._safe_get_attribute('largeImage')

@property
def images(self):
"""Large image entities: All large images for this item
:return:
A list with all the large size images URLs.
Primary image is always returned in the first position of the list
"""
return self.get_images_by_size('large')

@property
def product_tracking_url(self):
"""Product tracking url: Deep linked URL that directly links to the product page of this item on walmart.com.
Expand Down Expand Up @@ -601,6 +611,33 @@ def get_attribute(self, name):
"""
return self.response_handler._safe_get_attribute(name)

def get_images_by_size(self, size):
"""Image entities: All images for this item
:param size:
Indicates the size of the returned images: possible options are: 'thumbnail', 'medium', 'large'
:return:
A list with all the images URLs.
Primary image is always returned in the first position of the list
"""
if size != 'thumbnail' and size != 'medium' and size != 'large':
raise InvalidParameterException("The image size should be 'thumbnail', 'medium' or 'large'")
images = []
primary_image = None
imageEntities = self.response_handler._safe_get_attribute('imageEntities')
if imageEntities:
for image in imageEntities:
if image['entityType'] != 'PRIMARY':
images.append(image[size+'Image'])
else:
primary_image = image[size+'Image']
if primary_image:
images.insert(0, primary_image)
return images
else:
return None

class WalmartProductReview:
"""Models a Walmart Product review as an object
"""
Expand Down

0 comments on commit a8e8972

Please sign in to comment.