Skip to content

Commit

Permalink
Solved bugs and updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sergioteula committed Jul 15, 2020
1 parent 951341a commit 268adf8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion PRODUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
height
value
unit
lenght
length
value
unit
width
Expand Down
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:**
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions amazon/paapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions amazon/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='python-amazon-paapi',
version='3.2.0',
version='3.3.0',
author='Sergio Abad',
author_email='[email protected]',
description='Amazon Product Advertising API 5.0 wrapper for Python',
Expand Down

0 comments on commit 268adf8

Please sign in to comment.