示例#1
0
 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()
         })
示例#2
0
    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
示例#3
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
示例#4
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
示例#5
0
    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
示例#6
0
 def read_config(self, path):
     Wrapper.read_config(self, path)
示例#7
0
 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()})
示例#8
0
 def __init__(self):
     Wrapper.__init__(self, SERVICE)
示例#9
0
 def read_tokens(self, path):
     Wrapper.read_tokens(self, path)
     for row in self.tokens_reader:
         self.tokens.append({'applicationId': row[0].strip()})
示例#10
0
 def read_config(self, path):
     Wrapper.read_config(self, path)
示例#11
0
 def read_tokens(self, path):
     Wrapper.read_tokens(self, path)
     for row in self.tokens_reader:
         self.tokens.append({'applicationId': row[0].strip()})
示例#12
0
 def __init__(self):
     Wrapper.__init__(self, SERVICE)