Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added __init__.py
Empty file.
12 changes: 6 additions & 6 deletions make_endpoint/make_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ def to_class_name(s):


def get_endpoint_link(s):
return f""" endpoints/{s}
"""
return """ endpoints/{}
""".format(s)


def get_endpoint_file_template(s):
class_name = to_class_name(s)
return f"""{class_name}
{'=' * len(class_name)}
return """{}
{}


.. autoclass:: sp_api.api.{class_name}"""
.. autoclass:: sp_api.api.{}""".format(class_name, '=' * len(class_name), class_name)


def append_to_links(link):
Expand All @@ -33,7 +33,7 @@ def append_to_links(link):


def create_endpoint_file(file_contents, endpoint):
with open(f'../docs/endpoints/{endpoint}.rst', 'w+') as f:
with open('../docs/endpoints/{}.rst'.format(endpoint), 'w+') as f:
f.write(file_contents)
f.close()

Expand Down
24 changes: 12 additions & 12 deletions make_endpoint/make_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def make_py(endpoint, operations, description, directory):
template = env.get_template(file)
out = template.render(context)

with open(os.path.join(directory, f'{sub(endpoint)}.py'), 'w+') as f:
with open(os.path.join(directory, '{}.py'.format(sub(endpoint))), 'w+') as f:
f.write(out)
f.close()

Expand All @@ -47,7 +47,7 @@ def make_endpoint_name(s):


def make_directory(endpoint):
directory = f'../sp_api/api/{sub(endpoint)}'
directory = '../sp_api/api/{}'.format(sub(endpoint))
if os.path.exists(directory):
raise Exception('Directory exists')
os.mkdir(directory)
Expand All @@ -70,12 +70,12 @@ def make_params(params, model):

def add_to_init(endpoint):
e = sub(endpoint)
import_template = f'''##### DO NOT DELETE ########## INSERT IMPORT HERE #######
from .{e}.{e} import {endpoint}
'''
append_template = f'''##### DO NOT DELETE ########## INSERT TITLE HERE #######
"{endpoint}",
'''
import_template = '''##### DO NOT DELETE ########## INSERT IMPORT HERE #######
from .{}.{} import {}
'''.format(e, e, endpoint)
append_template = '''##### DO NOT DELETE ########## INSERT TITLE HERE #######
"{}",
'''.format(endpoint)
with open('../sp_api/api/__init__.py', 'r') as f:
content = f.read()
content = import_template.join(content.split('##### DO NOT DELETE ########## INSERT IMPORT HERE #######'))
Expand All @@ -87,10 +87,10 @@ def add_to_init(endpoint):


def add_to_setup_py(endpoint):
package = f"'sp_api.api.{sub(endpoint)}'"
append_template = f"""##### DO NOT DELETE ########## INSERT PACKAGE HERE #######
{package},
"""
package = "'sp_api.api.{}'".format(sub(endpoint))
append_template = """##### DO NOT DELETE ########## INSERT PACKAGE HERE #######
{},
""".format(package)
with open('../setup.py', 'r') as f:
content = f.read()
content = append_template.join(content.split('##### DO NOT DELETE ########## INSERT PACKAGE HERE #######'))
Expand Down
2 changes: 1 addition & 1 deletion sp_api/api/products/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def get_item_offers(self, asin: str, **kwargs) -> ApiResponse:

def _create_get_pricing_request(self, item_list, item_type, **kwargs):
return self._request(kwargs.pop('path'),
params={**{f"{item_type}s": ','.join(
params={**{"{}s".format(item_type): ','.join(
[urllib.parse.quote_plus(s) for s in item_list])},
'ItemType': item_type,
**({'ItemCondition': kwargs.pop(
Expand Down
4 changes: 2 additions & 2 deletions sp_api/auth/access_token_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def get_secret(self):
pass
else:
try:
return json.loads(secret.get(f'SP_API_ACCESS_TOKEN__{self._get_cache_key()}'))
return json.loads(secret.get('SP_API_ACCESS_TOKEN__{}'.format(self._get_cache_key())))
except TypeError:
return

Expand All @@ -155,7 +155,7 @@ def put_access_token(self, access_token):
SecretId=os.environ.get('SP_API_AWS_SECRET_ID')
)
secret = json.loads(response.get('SecretString'))
secret.update({f'SP_API_ACCESS_TOKEN__{self._get_cache_key()}': json.dumps(access_token)})
secret.update({'SP_API_ACCESS_TOKEN__{}'.format(self._get_cache_key()): json.dumps(access_token)})
client.put_secret_value(SecretId=os.environ.get('SP_API_AWS_SECRET_ID'), SecretString=json.dumps(secret))
except ClientError:
pass
2 changes: 1 addition & 1 deletion sp_api/base/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, account='default', credentials=None):
try:
import pkg_resources
version = pkg_resources.require("python-amazon-sp-api")[0].version
self.user_agent += f'-{version}'
self.user_agent += '-{}'.format(version)
except:
pass
self.credentials = CredentialProvider(account, credentials).credentials
14 changes: 7 additions & 7 deletions sp_api/base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, account='default', credentials=None):
self.credentials = self.Config(**credentials)
missing = self.credentials.check_config()
if len(missing):
raise MissingCredentials(f'The following configuration parameters are missing: {missing}')
raise MissingCredentials('The following configuration parameters are missing: {}'.format(missing))
else:
self.from_env()

Expand All @@ -45,7 +45,7 @@ def from_env(self):
self.read_config()

def _get_env(self, key):
return os.environ.get(f'{key}_{self.account}',
return os.environ.get('{}_{}'.format(key, self.account),
os.environ.get(key))

def read_config(self):
Expand All @@ -57,14 +57,14 @@ def read_config(self):
self.credentials = self.Config(**account_data)
missing = self.credentials.check_config()
if len(missing):
raise MissingCredentials(f'The following configuration parameters are missing: {missing}')
raise MissingCredentials('The following configuration parameters are missing: {}'.format(missing))
except confuse.exceptions.NotFoundError:
raise MissingCredentials(f'The account {self.account} was not setup in your configuration file.')
raise MissingCredentials('The account {} was not setup in your configuration file.'.format(self.account))
except confuse.exceptions.ConfigReadError:
raise MissingCredentials(
f'Neither environment variables nor a config file were found. '
f'Please set the correct variables, or use a config file (credentials.yml). '
f'See https://confuse.readthedocs.io/en/latest/usage.html#search-paths for search paths.'
'Neither environment variables nor a config file were found. '
'Please set the correct variables, or use a config file (credentials.yml). '
'See https://confuse.readthedocs.io/en/latest/usage.html#search-paths for search paths.'
)

class Config:
Expand Down
14 changes: 7 additions & 7 deletions sp_api/base/credential_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, account='default', credentials=None):
self.credentials = self.Config(**credentials)
missing = self.credentials.check_config()
if len(missing):
raise MissingCredentials(f'The following configuration parameters are missing: {missing}')
raise MissingCredentials('The following configuration parameters are missing: {}'.format(missing))
else:
self.load_credentials()

Expand Down Expand Up @@ -77,7 +77,7 @@ def from_env(self):
return len(self.credentials.check_config()) == 0

def _get_env(self, key):
return os.environ.get(f'{key}_{self.account}',
return os.environ.get('{}_{}'.format(key, self.account),
os.environ.get(key))

def read_config(self):
Expand All @@ -89,14 +89,14 @@ def read_config(self):
self.credentials = self.Config(**account_data)
missing = self.credentials.check_config()
if len(missing):
raise MissingCredentials(f'The following configuration parameters are missing: {missing}')
raise MissingCredentials('The following configuration parameters are missing: {}'.format(missing))
except confuse.exceptions.NotFoundError:
raise MissingCredentials(f'The account {self.account} was not setup in your configuration file.')
raise MissingCredentials('The account {} was not setup in your configuration file.'.format(self.account))
except confuse.exceptions.ConfigReadError:
raise MissingCredentials(
f'Neither environment variables nor a config file were found. '
f'Please set the correct variables, or use a config file (credentials.yml). '
f'See https://confuse.readthedocs.io/en/latest/usage.html#search-paths for search paths.'
'Neither environment variables nor a config file were found. '
'Please set the correct variables, or use a config file (credentials.yml). '
'See https://confuse.readthedocs.io/en/latest/usage.html#search-paths for search paths.'
)
else:
return True
Expand Down
42 changes: 21 additions & 21 deletions sp_api/base/marketplaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,29 @@ class Marketplaces(Enum):
marketplace_id = Marketplaces.UK.marketplace_id
"""

AE = (f"{BASE_URL}-eu.amazon.com", "A2VIGQ35RCS4UG", "eu-west-1")
DE = (f"{BASE_URL}-eu.amazon.com", "A1PA6795UKMFR9", "eu-west-1")
PL = (f"{BASE_URL}-eu.amazon.com", "A1C3SOZRARQ6R3", "eu-west-1")
EG = (f"{BASE_URL}-eu.amazon.com", "ARBP9OOSHTCHU", "eu-west-1")
ES = (f"{BASE_URL}-eu.amazon.com", "A1RKKUPIHCS9HS", "eu-west-1")
FR = (f"{BASE_URL}-eu.amazon.com", "A13V1IB3VIYZZH", "eu-west-1")
GB = (f"{BASE_URL}-eu.amazon.com", "A1F83G8C2ARO7P", "eu-west-1")
IN = (f"{BASE_URL}-eu.amazon.com", "A21TJRUUN4KGV", "eu-west-1")
IT = (f"{BASE_URL}-eu.amazon.com", "APJ6JRA9NG5V4", "eu-west-1")
NL = (f"{BASE_URL}-eu.amazon.com", "A1805IZSGTT6HS", "eu-west-1")
SA = (f"{BASE_URL}-eu.amazon.com", "A17E79C6D8DWNP", "eu-west-1")
SE = (f"{BASE_URL}-eu.amazon.com", "A2NODRKZP88ZB9", "eu-west-1")
TR = (f"{BASE_URL}-eu.amazon.com", "A33AVAJ2PDY3EV", "eu-west-1")
UK = (f"{BASE_URL}-eu.amazon.com", "A1F83G8C2ARO7P", "eu-west-1") # alias for GB
AE = ("{}-eu.amazon.com".format(BASE_URL), "A2VIGQ35RCS4UG", "eu-west-1")
DE = ("{}-eu.amazon.com".format(BASE_URL), "A1PA6795UKMFR9", "eu-west-1")
PL = ("{}-eu.amazon.com".format(BASE_URL), "A1C3SOZRARQ6R3", "eu-west-1")
EG = ("{}-eu.amazon.com".format(BASE_URL), "ARBP9OOSHTCHU", "eu-west-1")
ES = ("{}-eu.amazon.com".format(BASE_URL), "A1RKKUPIHCS9HS", "eu-west-1")
FR = ("{}-eu.amazon.com".format(BASE_URL), "A13V1IB3VIYZZH", "eu-west-1")
GB = ("{}-eu.amazon.com".format(BASE_URL), "A1F83G8C2ARO7P", "eu-west-1")
IN = ("{}-eu.amazon.com".format(BASE_URL), "A21TJRUUN4KGV", "eu-west-1")
IT = ("{}-eu.amazon.com".format(BASE_URL), "APJ6JRA9NG5V4", "eu-west-1")
NL = ("{}-eu.amazon.com".format(BASE_URL), "A1805IZSGTT6HS", "eu-west-1")
SA = ("{}-eu.amazon.com".format(BASE_URL), "A17E79C6D8DWNP", "eu-west-1")
SE = ("{}-eu.amazon.com".format(BASE_URL), "A2NODRKZP88ZB9", "eu-west-1")
TR = ("{}-eu.amazon.com".format(BASE_URL), "A33AVAJ2PDY3EV", "eu-west-1")
UK = ("{}-eu.amazon.com".format(BASE_URL), "A1F83G8C2ARO7P", "eu-west-1") # alias for GB

AU = (f"{BASE_URL}-fe.amazon.com", "A39IBJ37TRP1C6", "us-west-2")
JP = (f"{BASE_URL}-fe.amazon.com", "A1VC38T7YXB528", "us-west-2")
SG = (f"{BASE_URL}-fe.amazon.com", "A19VAU5U5O7RUS", "us-west-2")
AU = ("{}-fe.amazon.com".format(BASE_URL), "A39IBJ37TRP1C6", "us-west-2")
JP = ("{}-fe.amazon.com".format(BASE_URL), "A1VC38T7YXB528", "us-west-2")
SG = ("{}-fe.amazon.com".format(BASE_URL), "A19VAU5U5O7RUS", "us-west-2")

US = (f"{BASE_URL}-na.amazon.com", "ATVPDKIKX0DER", "us-east-1")
BR = (f"{BASE_URL}-na.amazon.com", "A2Q3Y263D00KWC", "us-east-1")
CA = (f"{BASE_URL}-na.amazon.com", "A2EUQ1WTGCTBG2", "us-east-1")
MX = (f"{BASE_URL}-na.amazon.com", "A1AM78C64UM0Y8", "us-east-1")
US = ("{}-na.amazon.com".format(BASE_URL), "ATVPDKIKX0DER", "us-east-1")
BR = ("{}-na.amazon.com".format(BASE_URL), "A2Q3Y263D00KWC", "us-east-1")
CA = ("{}-na.amazon.com".format(BASE_URL), "A2EUQ1WTGCTBG2", "us-east-1")
MX = ("{}-na.amazon.com".format(BASE_URL), "A1AM78C64UM0Y8", "us-east-1")

def __init__(self, endpoint, marketplace_id, region):
"""Easy dot access like: Marketplaces.endpoint ."""
Expand Down