From 8858d0053996e195a212ab7dd5f5a129029e7661 Mon Sep 17 00:00:00 2001 From: Patrick Lipka Date: Mon, 5 Apr 2021 01:52:59 +0200 Subject: [PATCH 1/3] Add _image_url variable and function get_image_path to get URL of product image --- python_picnic_api/client.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/python_picnic_api/client.py b/python_picnic_api/client.py index 937e7f7..72cf8f2 100644 --- a/python_picnic_api/client.py +++ b/python_picnic_api/client.py @@ -17,7 +17,7 @@ def __init__( self._base_url = _url_generator( DEFAULT_URL, self._country_code, DEFAULT_API_VERSION ) - + self._image_url = self._base_url+"/../../static/images" self.session = PicnicAPISession(auth_token=auth_token) # Login if not authenticated @@ -137,5 +137,15 @@ def print_categories(self, depth: int = 0): tree = "\n".join(_tree_generator(self.get_categories(depth=depth))) print(tree) + # Get full path of png image of size image_size for product with ID product_id + def get_image_path(self, image_id, image_size): + size_parameters = ['tiny','small','medium','large','extra-large'] + if (image_size not in size_parameters): + # fallback: set image size to medium + size='medium' + else: + size=image_size + path = self._image_url+"/"+image_id+"/"+size+".png" + return path __all__ = ["PicnicAPI"] From 5ecc794b97e282cd17395b9fb1a2907b2204e55d Mon Sep 17 00:00:00 2001 From: Patrick Lipka Date: Mon, 5 Apr 2021 02:06:14 +0200 Subject: [PATCH 2/3] code formatting corrected for get:image_path --- python_picnic_api/client.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python_picnic_api/client.py b/python_picnic_api/client.py index 72cf8f2..60e70c6 100644 --- a/python_picnic_api/client.py +++ b/python_picnic_api/client.py @@ -139,13 +139,14 @@ def print_categories(self, depth: int = 0): # Get full path of png image of size image_size for product with ID product_id def get_image_path(self, image_id, image_size): - size_parameters = ['tiny','small','medium','large','extra-large'] + size_parameters = ['tiny', 'small', 'medium', 'large', 'extra-large'] if (image_size not in size_parameters): # fallback: set image size to medium - size='medium' + size = 'medium' else: - size=image_size + size = image_size path = self._image_url+"/"+image_id+"/"+size+".png" return path + __all__ = ["PicnicAPI"] From e129a4cc581354ded310319c58475a75f6578599 Mon Sep 17 00:00:00 2001 From: Patrick Lipka Date: Mon, 5 Apr 2021 02:08:00 +0200 Subject: [PATCH 3/3] remove trailing white space in get_image_path --- python_picnic_api/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python_picnic_api/client.py b/python_picnic_api/client.py index 60e70c6..9646773 100644 --- a/python_picnic_api/client.py +++ b/python_picnic_api/client.py @@ -145,7 +145,7 @@ def get_image_path(self, image_id, image_size): size = 'medium' else: size = image_size - path = self._image_url+"/"+image_id+"/"+size+".png" + path = self._image_url+"/"+image_id+"/"+size+".png" return path