<commit_before># -*- coding: utf-8 -*-

""" Interface to Amazon API """
from os import getenv
from amazon.api import AmazonAPI


class Amazon(AmazonAPI):
	"""An Amazon search"""

	def __init__(self, region='US', **kwargs):
		"""
		Initialization method.

		Parameters
		----------
		key : AWS_ACCESS_KEY_ID
		secret : AWS_SECRET_ACCESS_KEY
		tag : AWS_ASSOCIATE_TAG
		region : string
			one of  ['US', 'FR', 'UK', 'CA', 'DE', 'JP', 'IT', 'ES']

		Keyword Arguments
		-----------------
		see bottlenose docs

		Returns
		-------
		New instance of :class:`Amazon` : Amazon

		Examples
		--------
		>>> Amazon()  #doctest: +ELLIPSIS
		<app.api.Amazon object at 0x...>
		"""
		key = kwargs.pop('key', getenv('AWS_ACCESS_KEY_ID'))
		secret = kwargs.pop('secret', getenv('AWS_SECRET_ACCESS_KEY'))
		tag = kwargs.pop('tag', getenv('AWS_ASSOCIATE_TAG'))
		region = kwargs.pop('region', 'US')

		if not (key and secret and tag):
			raise SystemExit('Error getting Amazon credentials.')

		super(Amazon, self).__init__(key, secret, tag, region)

	def parse(self, response):
		"""
		Convert Amazon API search response into a more readable format.

		Parameters
		----------
		response : AmazonSearch object

		Returns
		-------
		Cleaned up search results : dict

		Examples
		--------
		>>> amazon = Amazon()
		>>> kwargs = {'SearchIndex': 'All', 'Keywords': 'Harry Potter', \
'ResponseGroup': 'Medium'}
		>>> amzn_response = amazon.search_n(1, **kwargs)
		>>> amazon.parse(amzn_response)[0].keys()
		['asin', 'title', 'url', 'price', 'currency', 'sales_rank', 'model']
		"""
		items = []

		for r in response:
			item = {
				'asin': r.asin,<commit_msg>Fix region bug<commit_after># -*- coding: utf-8 -*-

""" Interface to Amazon API """
from os import getenv
from amazon.api import AmazonAPI


class Amazon(AmazonAPI):
	"""An Amazon search"""

	def __init__(self, region='US', **kwargs):
		"""
		Initialization method.

		Parameters
		----------
		key : AWS_ACCESS_KEY_ID
		secret : AWS_SECRET_ACCESS_KEY
		tag : AWS_ASSOCIATE_TAG
		region : string
			one of  ['US', 'FR', 'UK', 'CA', 'DE', 'JP', 'IT', 'ES']

		Keyword Arguments
		-----------------
		see bottlenose docs

		Returns
		-------
		New instance of :class:`Amazon` : Amazon

		Examples
		--------
		>>> Amazon()  #doctest: +ELLIPSIS
		<app.api.Amazon object at 0x...>
		"""
		key = kwargs.pop('key', getenv('AWS_ACCESS_KEY_ID'))
		secret = kwargs.pop('secret', getenv('AWS_SECRET_ACCESS_KEY'))
		tag = kwargs.pop('tag', getenv('AWS_ASSOCIATE_TAG'))

		if not (key and secret and tag):
			raise SystemExit('Error getting Amazon credentials.')

		super(Amazon, self).__init__(key, secret, tag, region)

	def parse(self, response):
		"""
		Convert Amazon API search response into a more readable format.

		Parameters
		----------
		response : AmazonSearch object

		Returns
		-------
		Cleaned up search results : dict

		Examples
		--------
		>>> amazon = Amazon()
		>>> kwargs = {'SearchIndex': 'All', 'Keywords': 'Harry Potter', \
'ResponseGroup': 'Medium'}
		>>> amzn_response = amazon.search_n(1, **kwargs)
		>>> amazon.parse(amzn_response)[0].keys()
		['asin', 'title', 'url', 'price', 'currency', 'sales_rank', 'model']
		>>> amazon = Amazon(region='UK')
		>>> amzn_response = amazon.search_n(1, **kwargs)
		>>> url = amazon.parse(amzn_response)[0]['url']
		>>> '.'.join(url.split('/')[2].split('.')[2:])
		'co.uk'
		"""
		items = []

		for r in response:
			item = {
				'asin': r.asin,
{'fraction_non_alphanumeric': 0.19907138711549624, 'fraction_numerical': 0.003482298316889147, 'mean_word_length': 3.208791208791209, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7000548', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1161, 'n_words': 299}