-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Module to manage items""" | ||
|
||
from typing import List | ||
from .. import models | ||
|
||
|
||
def sort_items(items: List[models.Item], items_ids: List[str], include_unavailable: bool) -> List[models.Item]: | ||
sorted_items = [] | ||
|
||
for asin in items_ids: | ||
matches = list(filter(lambda item, asin=asin: item.asin == asin, items)) | ||
if matches: | ||
sorted_items.append(matches[0]) | ||
elif include_unavailable: | ||
sorted_items.append(models.Item(asin=asin)) | ||
|
||
return sorted_items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
"""Some useful tools.""" | ||
|
||
from ..errors import AsinNotFoundException | ||
import re | ||
from ..errors import AsinNotFoundException | ||
|
||
|
||
def get_asin(text: str) -> str: | ||
"""Returns the ASIN from a given text. Raises AsinNotFoundException on fail.""" | ||
# Return if text is an ASIN | ||
if re.search(r'^[A-Z0-9]{10}$', text): | ||
return text | ||
if re.search(r'^[a-zA-Z0-9]{10}$', text): | ||
return text.upper() | ||
|
||
# Extract ASIN from URL searching for alphanumeric and 10 digits | ||
asin = re.search(r'(dp|gp/product|gp/aw/d|dp/product)/([a-zA-Z0-9]{10})', text) | ||
if asin: | ||
return asin.group(2) | ||
else: | ||
raise AsinNotFoundException('Asin not found: ' + text) | ||
return asin.group(2).upper() | ||
|
||
raise AsinNotFoundException('Asin not found: ' + text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setuptools.setup( | ||
name='python-amazon-paapi', | ||
version='4.1.1', | ||
version='4.2.0', | ||
author='Sergio Abad', | ||
author_email='[email protected]', | ||
description='Amazon Product Advertising API 5.0 wrapper for Python', | ||
|