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
Exemple #2
0
    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