diff --git a/PRODUCT.md b/PRODUCT.md index a7c4df7..edcabed 100644 --- a/PRODUCT.md +++ b/PRODUCT.md @@ -17,7 +17,7 @@ height value unit - lenght + length value unit width diff --git a/README.md b/README.md index 6652f20..39df8df 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Features * Get browse nodes information. * Get multiple results at once without the 10 items limitation from Amazon. * Configurable throttling to avoid requests exceptions. +* Built-in serializer for Django REST framework. * Support for [all available countries](https://github.com/sergioteula/python-amazon-paapi/blob/master/amazon/paapi.py#L31). * Reorganized product information [structure](https://github.com/sergioteula/python-amazon-paapi/blob/master/PRODUCT.md) for simple use. * Ask for new features through the [issues](https://github.com/sergioteula/python-amazon-paapi/issues) section. @@ -30,6 +31,10 @@ You can install or upgrade the module with: pip install python-amazon-paapi --upgrade +If you get `ModuleNotFoundError`, try installing this: + + pip install amightygirl.paapi5-python-sdk + Usage guide ----------- **Basic usage:** @@ -75,34 +80,32 @@ Throttling value must be `greater than 0` or `False` to disable it. This value t amazon = AmazonAPI(KEY, SECRET, TAG, COUNTRY, throttling=0.5) # Max one request every two seconds amazon = AmazonAPI(KEY, SECRET, TAG, COUNTRY, throttling=False) # Unlimited requests per second -**API support** -We provide a serializer for django rest framework, which speeds up your api +**Serializer for Django:** + +We provide a serializer for Django REST framework, which speeds up your API implementation. - from amazon.paapi import AmazonAPI from amazon.serializers import AmazonProductSerializer from rest_framework import serializers - amazon = AmazonAPI(KEY, SECRET, TAG, COUNTRY) - product = amazon.get_product('B01N5IB20Q') serialized_product = AmazonProductSerializer(product) - serialized.data # this prints serialized product + serialized_product.data -if you like to serialize a list of products: +If you want to serialize a list of products: - products = amazon.search_products(item_count=40, keywords='Harry') serialized_products = AmazonProductSerializer(products, many=True) serialized_products.data -For more Information how to work with serializers see the documentation of -[django rest framework](https://www.django-rest-framework.org/api-guide/serializers/) +For more information on how to work with serializers, check the documentation for +[Django REST framework](https://www.django-rest-framework.org/api-guide/serializers/). Changelog ------------- - Version 3.2.1 (unreleased) - - Added serializer class for django rest framework - - Added serialized data for your convenience + Version 3.3.0 + - Added serializer class for Django REST framework. + - Solved bugs and typos. + Version 3.2.0 - Added new method for getting browse nodes information. - Removed the 10 pages limit on search_products and get_variations methods. diff --git a/amazon/paapi.py b/amazon/paapi.py index f7f06ea..dc5da06 100644 --- a/amazon/paapi.py +++ b/amazon/paapi.py @@ -164,8 +164,12 @@ def get_product(self, product_id: str, condition='Any', merchant='All', if len(check_product_id) > 1: raise AmazonException('ValueError', 'Only 1 product ID is allowed, use ' 'get_products for multiple requests') - return self.get_products(product_id, condition=condition, merchant=merchant, - async_req=async_req)[0] + product = self.get_products(product_id, condition=condition, merchant=merchant, + async_req=async_req) + if product: + return product[0] + else: + return None def search_products(self, item_count=10, item_page=1, items_per_page=10, keywords=None, actor=None, artist=None, author=None, brand=None, title=None, diff --git a/amazon/parse.py b/amazon/parse.py index 246c507..766b093 100644 --- a/amazon/parse.py +++ b/amazon/parse.py @@ -225,15 +225,15 @@ def parse_product(item): product.product.dimensions.height.unit = item.item_info.product_info.item_dimensions.height.unit except Exception: product.product.dimensions.height.unit = None - product.product.dimensions.lenght = Class() + product.product.dimensions.length = Class() try: - product.product.dimensions.lenght.value = item.item_info.product_info.item_dimensions.lenght.display_value + product.product.dimensions.length.value = item.item_info.product_info.item_dimensions.length.display_value except Exception: - product.product.dimensions.lenght.value = None + product.product.dimensions.length.value = None try: - product.product.dimensions.lenght.unit = item.item_info.product_info.item_dimensions.lenght.unit + product.product.dimensions.length.unit = item.item_info.product_info.item_dimensions.length.unit except Exception: - product.product.dimensions.lenght.unit = None + product.product.dimensions.length.unit = None product.product.dimensions.width = Class() try: product.product.dimensions.width.value = item.item_info.product_info.item_dimensions.width.display_value diff --git a/setup.py b/setup.py index 51e5e88..403568b 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name='python-amazon-paapi', - version='3.2.0', + version='3.3.0', author='Sergio Abad', author_email='sergio.abad@bytelix.com', description='Amazon Product Advertising API 5.0 wrapper for Python',