def read_tokens(self, path): Wrapper.read_tokens(self, path) for row in self.tokens_reader: self.tokens.append({ 'ACCESS_KEY': row[0].strip(), 'SECRET_KEY': row[1].strip(), 'ASSOC_TAG': row[2].strip(), 'LOCALE': row[3].strip() })
def single_access(self, token, option=None): Wrapper.single_access(self,token) result = {} try: asin = option['item'] amazon = AmazonAPI(token['ACCESS_KEY'], token['SECRET_KEY'], token['ASSOC_TAG'], region=token['LOCALE']) data = amazon.lookup(ItemId=asin) result['raw'] = data result['title'] = data.title result['category'] = data.get_attribute('ProductGroup') except: # If any exceptions happen, return None sys.stderr.write("Unexpected error accessing API:\n\t%s\n\t%s" % (sys.exc_info()[0], sys.exc_info()[1])) result = None return result
def single_access(self, token, option=None): Wrapper.single_access(self, token) result = {} if option is not None: try: item_id = option['item'] if 'type' in option and option['type'] == "genre": payload = { "format": "json", "genreId": item_id, "applicationId": token['applicationId'] } r = requests.get(API_GENRE_BASE, params=payload) data = r.json() if not data['parents']: result['genre'] = data['current']['genreName'] else: result['genre'] = data['parents'][0]['parent'][ 'genreName'] elif 'type' not in option: payload = { "format": "json", "itemCode": item_id, "applicationId": token['applicationId'] } r = requests.get(API_ITEM_BASE, params=payload) data = r.json() item = data['Items'][0]['Item'] result['raw'] = item result['title'] = item['itemName'] result['url'] = item['itemUrl'] result['category_id'] = item['genreId'] opt = {"item": result["category_id"], "type": "genre"} result['category'] = self.access_wrapper(opt)['genre'] else: result = None except: # If any exceptions happen, return None sys.stderr.write( "Unexpected error accessing API:\n\t%s\n\t%s" % (sys.exc_info()[0], sys.exc_info()[1])) result = None return result
def single_access(self, token, option=None): Wrapper.single_access(self,token) result = {} if option is not None: try: item_id = option['item'] if 'type' in option and option['type'] == "genre": payload = { "format": "json", "genreId": item_id, "applicationId": token['applicationId'] } r = requests.get(API_GENRE_BASE, params=payload) data = r.json() if not data['parents']: result['genre'] = data['current']['genreName'] else: result['genre'] = data['parents'][0]['parent']['genreName'] elif 'type' not in option: payload = { "format": "json", "itemCode": item_id, "applicationId": token['applicationId'] } r = requests.get(API_ITEM_BASE, params=payload) data = r.json() item = data['Items'][0]['Item'] result['raw'] = item result['title'] = item['itemName'] result['url'] = item['itemUrl'] result['category_id'] = item['genreId'] opt = {"item": result["category_id"], "type": "genre"} result['category'] = self.access_wrapper(opt)['genre'] else: result = None except: # If any exceptions happen, return None sys.stderr.write("Unexpected error accessing API:\n\t%s\n\t%s" % (sys.exc_info()[0], sys.exc_info()[1])) result = None return result
def single_access(self, token, option=None): Wrapper.single_access(self, token) result = {} try: asin = option['item'] amazon = AmazonAPI(token['ACCESS_KEY'], token['SECRET_KEY'], token['ASSOC_TAG'], region=token['LOCALE']) data = amazon.lookup(ItemId=asin) result['raw'] = data result['title'] = data.title result['category'] = data.get_attribute('ProductGroup') except: # If any exceptions happen, return None sys.stderr.write("Unexpected error accessing API:\n\t%s\n\t%s" % (sys.exc_info()[0], sys.exc_info()[1])) result = None return result
def read_config(self, path): Wrapper.read_config(self, path)
def read_tokens(self, path): Wrapper.read_tokens(self, path) for row in self.tokens_reader: self.tokens.append({'ACCESS_KEY': row[0].strip(), 'SECRET_KEY': row[1].strip(), 'ASSOC_TAG': row[2].strip(), 'LOCALE': row[3].strip()})
def __init__(self): Wrapper.__init__(self, SERVICE)
def read_tokens(self, path): Wrapper.read_tokens(self, path) for row in self.tokens_reader: self.tokens.append({'applicationId': row[0].strip()})