예제 #1
0
    def __init__(self):
        self.searchMethod = "word"
        #self.searchMethod = "word"
        self.country = "JP"
        '''
        self.ACCESS_KEY = "hogehoge"
        self.SECRET_ACCESS_KEY = "hogehoge"
        self.ASSOCIATE_TAG = "hogehoge"
        
        
        self.ACCESS_KEY = "hogehoge"
        self.SECRET_ACCESS_KEY = "hogehoge"
        self.ASSOCIATE_TAG = "hogehoge"
        
        self.ACCESS_KEY = "hogehoge"
        self.SECRET_ACCESS_KEY = "hogehoge"
        self.ASSOCIATE_TAG = "hogehoge"
        
        
        '''

        self.ACCESS_KEY = "hogehoge"
        self.SECRET_ACCESS_KEY = "hogehoge"
        self.ASSOCIATE_TAG = "hogehoge"

        self.dbname = r'D:\workspace\sqlite\sample.sqlite3'
        if os.path.exists(self.dbname) is False:
            self.dbname = r'C:\Users\VJP1311\workspace\sqlite\sample.sqlite3'

        self.amazon = bottlenose.Amazon(self.ACCESS_KEY,
                                        self.SECRET_ACCESS_KEY,
                                        self.ASSOCIATE_TAG,
                                        Region=self.country)
예제 #2
0
    def get_albums(self, query, va_likely):
        """Returns a list of AlbumInfo objects for a Amazon search query.
        """
        # Strip non-word characters from query. Things like "!" and "-" can
        # cause a query to return no results, even if they match the artist or
        # album title. Use `re.UNICODE` flag to avoid stripping non-english
        # word characters.
        query = re.sub(r'(?u)\W+', ' ', query)
        # Strip medium information from query, Things like "CD1" and "disk 1"
        # can also negate an otherwise positive result.
        query = re.sub(r'(?i)\b(CD|disc)\s*\d+', '', query)
        albums = []
        amazon = bottlenose.Amazon(
             self.Access_Key_ID, str(self.Secret_Access_Key), self.asso_tag
        )
        response = amazon.ItemSearch(
            SearchIndex="Music",
            Keywords=query,
            ResponseGroup="Tracks,ItemAttributes"
        )
        root = ET.fromstring(response)
        nsregx = re.compile('^({.+?})')
        ns = nsregx.search(root.tag).group(1)

        for item in root.findall(".//{0}Tracks/..". format(ns)):
            albums.append(self.get_album_info(item, ns, va_likely))
            if len(albums) >= 5:
                break
        log.debug('get_albums_Searching amazon for release %s' % str(query))
        return albums
예제 #3
0
 def __init__(self, AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG):
     self.AMAZON_ACCESS_KEY = AMAZON_ACCESS_KEY
     self.AMAZON_SECRET_KEY = AMAZON_SECRET_KEY
     self.AMAZON_ASSOC_TAG = AMAZON_ASSOC_TAG
     self.MAX_RETRY = 5
     self.api = bottlenose.Amazon(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY,
                                  AMAZON_ASSOC_TAG)
예제 #4
0
파일: main.py 프로젝트: jakerose27/1rating
def diff():
    search_text = request.form['search']
    thing = bottlenose.Amazon('AKIAJV4MVIAB5Z7BOH5Q',
                              'cnZViZA5pXHNxYHOZmJ2hRPSpW78G+hQsSFAjoBR',
                              '*****@*****.**')

    response = thing.ItemSearch(Keywords=search_text, SearchIndex="All")
    root = etree.fromstring(response)
    ASIN = root[1][4][0].text
    reviews = thing.ItemLookup(ItemId=ASIN, ResponseGroup="Reviews")
    reviews = etree.fromstring(reviews)
    print etree.tostring(reviews, pretty_print=True)
    iframe_url = reviews.getchildren()[1].getchildren()[1].getchildren(
    )[-1].getchildren()[0].text
    search_title = root.getchildren()[1].getchildren()[4].getchildren(
    )[-1].getchildren()[-1].text

    class MyHTMLParser(HTMLParser):
        def handle_startendtag(self, tag, attrs):
            if tag == "img":
                for item in attrs:
                    if item[0] == "src":
                        if item[1].startswith(
                                "http://g-ecx.images-amazon.com/images/G/01/x-locale/common/customer-reviews/ratings/"
                        ):
                            self.rating = attrs[2][1].split(" ")[0]

    data = urllib.urlopen(iframe_url).read()  # open iframe src url
    parse = MyHTMLParser()
    parse.feed(data)
    # print etree.tostring(tree, pretty_print=True)
    return render_template("search.html",
                           iframe_url=iframe_url,
                           search_title=search_title,
                           rating=parse.rating)
예제 #5
0
파일: views.py 프로젝트: sycct/wikitowns
def create_book_recommendation(request, category_name_slug,
                               subcategory_name_slug):
    context_dict = {}
    user = request.user
    category = get_object_or_404(Category, slug=category_name_slug)
    context_dict['category'] = category
    subcategory = get_object_or_404(SubCategory,
                                    slug=subcategory_name_slug,
                                    category=category)
    context_dict['subcategory'] = subcategory
    form = BookForm(category=category, subcategory=subcategory)

    AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
    AWS_SECRET_ACCESS_KEY = os.environ['AWS_SECRET_ACCESS_KEY']
    AWS_ASSOCIATE_TAG = os.environ['AWS_ASSOCIATE_TAG']

    amazon = bottlenose.Amazon(AWS_ACCESS_KEY_ID,
                               AWS_SECRET_ACCESS_KEY,
                               AWS_ASSOCIATE_TAG,
                               Parser=lambda text: BeautifulSoup(text, 'xml'))
    if request.method == "POST":
        form = BookForm(request.POST,
                        category=category,
                        subcategory=subcategory)
        if form.is_valid():
            isbn = (form.cleaned_data['isbn'])
            book = form.save(commit=False)

            try:
                results = amazon.ItemLookup(ItemId=isbn,
                                            ResponseGroup="Medium",
                                            SearchIndex="Books",
                                            IdType="ISBN")
                date_published = results.find('PublicationDate').string
                # some amazon books only return the year and not the full date
                if len(date_published) == 4:
                    date_published = "%s-01-01" % date_published
                book.book_publish_date = date_published
                # review line below - dont think it is a good way of doing it
                book.book_image_url = results.find('LargeImage').text[:-6]
                book.recommended_by = user
                book.category = category
                book.subcategory = subcategory
                book.title = results.find('Title').string
                book.book_author = results.find('Author').string
                book.book_description = results.find('Content').string
                book.book_url = results.find('DetailPageURL').string
                book.save()
                return redirect('subcategory',
                                category_name_slug=category.slug,
                                subcategory_name_slug=subcategory.slug)
            except:
                messages.error(request, ("Something went wrong, please try "
                                         "again. If this error keeps showing "
                                         "then there may be an issue with "
                                         "the book you are trying to "
                                         "recommend."))

    context_dict['form'] = form
    return render(request, 'website/create_book.html', context_dict)
예제 #6
0
def get_amazon_by_region(region):
    access_key = "AKIAIN7FKTAMCSG7VVOA"
    secret = "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"
    if region == 'us':
        return bottlenose.Amazon(access_key,
                                 secret,
                                 "gary62107-20",
                                 ErrorHandler=error_handler)
    elif region == 'jp':
        return bottlenose.Amazon(access_key,
                                 secret,
                                 "gary62107-22",
                                 Region="JP",
                                 ErrorHandler=error_handler)
    else:
        return None
예제 #7
0
    def album_for_id(self, asin):
        """Fetches an album by its amazon ID and returns an AlbumInfo object
        or None if the album is not found.
        """
        log.debug('Searching amazon for release %s' % str(asin))

        for region in self.preferred_regions:
            amazon = bottlenose.Amazon(
                self.Access_Key_ID,
                str(self.Secret_Access_Key),
                self.asso_tag,
                None,
                "2013-08-01",
                region)
            response = amazon.ItemLookup(
                ItemId=asin,
                ResponseGroup="Tracks,ItemAttributes"
            )
            root = ET.fromstring(response)
            nsregx = re.compile('^({.+?})')
            ns = nsregx.search(root.tag).group(1)

            item = root.find(".//{0}Tracks/..".format(ns))
            if item :
                return self.get_album_info(item, ns, False)
        return None
예제 #8
0
def get_product_attributes(product_id, credentials):
    """ The function takes a product id and dictionary of 
    credentials which should be in the form of:
    
      {'AWSAccessKeyId': your_key,
      'AWSSecretAccessKey': private_key,
      'AssociateTag': your_tag}
      
    which are used for authentication. It returns a JSON string which will be
    saved and loaded to a DB later."""

    access_key = credentials['AWSAccessKeyId']
    secret_key = credentials['AWSSecretAccessKey']
    assoc_tag = credentials['AssociateTag']

    # setyp API object with credentials
    amazon = bottlenose.Amazon(AWSAccessKeyId=access_key,
                               AWSSecretAccessKey=secret_key,
                               AssociateTag=assoc_tag,
                               MaxQPS=0.8)

    # request attributes and SalesRank for the product id
    response = amazon.ItemLookup(ItemId=product_id,
                                 ResponseGroup="ItemAttributes,SalesRank")

    # the response comes in as an XML string: to access it like a,
    # typical Python object convert it to a dictionary (python object)
    response_dict = dict(xmltodict.parse(response))

    # create a top-level identifier using the product id, then store the nested
    # response
    response_dict = {'product_asin': product_id, 'api_response': response_dict}

    # return the dictionary
    return response_dict
예제 #9
0
 def queryAmazon(self, prodList, rgp=''):
     amazon = bottlenose.Amazon('', '', '')
     itemdict = []
     db = self.db
     lis = list(db['Item'])
     for item in prodList:
         if item in lis:
             if len(rgp) != 0:
                 value = db[db['Item'] == item]['Image'].values[0]
             else:
                 value = db[db['Item'] == item]['ProductName'].values[0]
         else:
             try:
                 response = amazon.ItemLookup(ItemId=item,
                                              ResponseGroup=rgp)
                 soup = BeautifulSoup(response, "xml")
                 if len(rgp) != 0:
                     value = soup.MediumImage.URL.string
                 else:
                     value = soup.ItemAttributes.Title.string
             except:
                 value = ""
                 pass
         itemdict.append(value)
     return itemdict
예제 #10
0
 def get_product_from_amazon_api(self, asin, region='US'):
     try:
         amazon = bottlenose.Amazon(self.AWS_ACCESS_KEY_ID,
                                    self.AWS_SECRET_ACCESS_KEY,
                                    self.AWS_ASSOCIATE_TAG,
                                    Region=region)
         response = amazon.ItemLookup(ItemId=asin, ResponseGroup="Large")
         parsed = BeautifulSoup(response, "lxml")
         logging.info(parsed.error)
         logging.info(parsed.productgroup)
         if self.error_check_amazon_api(parsed.error):
             title = parsed.title.text
             product_group_string = parsed.productgroup.text
             url = "https://www.amazon.com/dp/%s/" % asin
             image_url = parsed.mediumimage.url.text
             return {
                 'title': title,
                 'product_group_string': product_group_string,
                 'url': url,
                 'image_url': image_url
             }
         else:
             logging.info("Error from Amazon" + parsed.error)
             url = "https://www.amazon.com/dp/%s/" % asin
             return {
                 'title': '',
                 'product_group_string': 'Unknown',
                 'url': url,
                 'image_url': ''
             }
     except Exception as e:
         print e
예제 #11
0
 def __init__(self,**kwargs):
     self.AWS_ACCESS_KEY_ID = kwargs['id']
     self.AWS_SECRET_ACCESS_KEY = kwargs['key']
     self.AWS_ASSOCIATE_TAG = kwargs['tag']
     self.item_path = item_path
     self.attr_paths = attr_paths
     self.amazon_api = bottlenose.Amazon(kwargs['id'],kwargs['key'],kwargs['tag'])
예제 #12
0
def fetchBookItems(node, page):
	items = []
	try:
		amazon = bottlenose.Amazon(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_ASSOCIATE_TAG, 
			Parser=lambda text: BeautifulSoup(text, 'html5lib'), MaxQPS=1.1)
		response = amazon.ItemSearch(ItemPage=page, BrowseNode=node, SearchIndex="KindleStore", MaximumPrice="0", 
			Sort="salesrank", ResponseGroup="AlternateVersions,ItemAttributes,EditorialReview,Images,BrowseNodes",
			Keywords=BLACKLIST_WORDS_AMAZON)
		
		items = copy.copy(response.items)
		response.decompose()
	except Exception as e:
		try:
			print "Error when fetching book items, retrying.", e
			time.sleep(10)
			response = amazon.ItemSearch(ItemPage=page, BrowseNode=node, SearchIndex="KindleStore", MaximumPrice="0", 
				Sort="salesrank", ResponseGroup="AlternateVersions,ItemAttributes,EditorialReview,Images,BrowseNodes",
				Keywords=BLACKLIST_WORDS_AMAZON)
			
			items = copy.copy(response.items)
			response.decompose()
		except Exception as e:
			print "Error when fetching book items a second time.", e
			print e, node
			time.sleep(10)

	return items
예제 #13
0
def amazon(isbn):
    """Given an Amazon URL, get title, creator, etc. from imdapi.com
    """

    aws_key = AMZ['KEY']
    aws_secret_key = AMZ['SECRET_KEY']
    aws_associate_tag = AMZ['ASSOCIATE_TAG']
    blob = {}

    amazon = bottlenose.Amazon(aws_key, aws_secret_key, aws_associate_tag)
    response = amazon.ItemLookup(ItemId=isbn,
                                 ResponseGroup="BrowseNodes",
                                 IdType="ISBN",
                                 SearchIndex="Books")

    xml = parseString(response)

    nodes = xml.getElementsByTagName('Children')
    for node in nodes:
        parent = node.parentNode
        parent.removeChild(node)

    categories = []
    for book in xml.getElementsByTagName('Name'):
        category = str(book.firstChild.nodeValue)
        categories.append(category)

    taglists = []
    while 'Books' in categories:
        find = categories.index('Books') + 1
        list = categories[:find]
        if 'Products' not in list:
            taglists.append(list)
        for word in list:
            categories.remove(word)

    subjects = []
    #now, we only return the first item from a list which contains 'Subjects'
    for tagset in taglists:
        while 'Subjects' in tagset:
            tagset.pop(tagset.index('Subjects'))
            tagset.pop(tagset.index('Books'))
            for subject in tagset:
                subjects.append(subject)

    if subjects:
        subjects.sort()
        last = subjects[-1]
        for i in range(len(subjects) - 2, -1, -1):
            if last == subjects[i]:
                del subjects[i]
            else:
                last = subjects[i]

    blob['subjects'] = ':::'.join(subjects)
    blob['cats'] = taglists

    for subject in subjects:
        _insert_amazon_subject(isbn, subject)
예제 #14
0
 def __init__(self):
     self._api = bottlenose.Amazon(ke.AMAZON_ACCESS_KEY_ID,
                                   ke.AMAZON_ACCESS_SECRET_KEY,
                                   ke.AMAZON_ASSOCIATE_TAG, Region="US",
                                   Version='2013-08-01')
     self.results = []
     self.reviews = []
     self.count = 0
예제 #15
0
def getAccessToken():

    myAWSId = 'Yout-AWS-ID'
    myAWSSecret = 'AWS-Secret'
    myEndPoint = 'AWS-Endpoint'

    amazon = bottlenose.Amazon(myAWSId, myAWSSecret, Version="2009-10-01")
    return amazon
예제 #16
0
	def __init__(self):
		AWSAccessKeyId="ID"
		AWSSecretKey="PW"
		AssosiateId = "ID"
		amazon = bottlenose.Amazon(AWSAccessKeyId,
                           AWSSecretKey,
                           AssosiateId ,
                           Region='JP')
		self.amazon = amazon
예제 #17
0
    def __init__(self, aws_key, aws_secret, aws_associate_tag, **kwargs):
        """Initialize an Amazon API Proxy.

        kwargs values are passed directly to Bottlenose. Check the Bottlenose
        API for valid values (some are provided below).
        For legacy support, the older 'region' value is still supported.
        Code should be updated to use the Bottlenose 'Region' value
        instead.

        :param aws_key:
            A string representing an AWS authentication key.
        :param aws_secret:
            A string representing an AWS authentication secret.
        :param aws_associate_tag:
            A string representing an AWS associate tag.

        Important Bottlenose arguments:
        :param Region:
            ccTLD you want to search for products on (e.g. 'UK'
            for amazon.co.uk).
            See keys of bottlenose.api.SERVICE_DOMAINS for options, which were
            CA, CN, DE, ES, FR, IT, JP, UK, US at the time of writing.
            Must be uppercase. Default is 'US' (amazon.com).
        :param MaxQPS:
            Optional maximum queries per second. If we've made an API call
            on this object more recently that 1/MaxQPS, we'll wait
            before making the call. Useful for making batches of queries.
            You generally want to set this a little lower than the
            max (so 0.9, not 1.0).
            Amazon limits the number of calls per hour, so for long running
            tasks this should be set to 0.9 to ensure you don't hit the maximum.
            Defaults to None (unlimited).
        :param Timeout:
            Optional timeout for queries.
            Defaults to None.
        :param CacheReader:
            Called before attempting to make an API call.
            A function that takes a single argument, the URL that
            would be passed to the API, minus auth information,
            and returns a cached version of the (unparsed) response,
            or None.
            Defaults to None.
        :param CacheWriter:
            Called after a successful API call. A function that
            takes two arguments, the same URL passed to
            CacheReader, and the (unparsed) API response.
            Defaults to None.
        """
        # support older style calls
        if 'region' in kwargs:
            kwargs['Region'] = kwargs['region']
            del kwargs['region']
        self.api = bottlenose.Amazon(
            aws_key, aws_secret, aws_associate_tag, **kwargs)
        self.aws_associate_tag = aws_associate_tag
        self.region = kwargs.get('Region', 'US')
예제 #18
0
def amz_api_call(media, source_name):
    # set director to get better amz results for movies
    title = media['title']
    director = ''
    if media['mtype'] == 'movie' and 'credits' in media:
        crew = media['credits']['crew']
        director = [c['name'] for c in crew if c['job'] == 'Director']
        director = director[0] if director else ''
        director = director.replace('Dave', 'David')
        if title == 'Terminator Genisys':  # put misspelling so will match
            director = director.replace('Taylor', 'Talyor')

    # prepare bottlenose object for amz search
    with open('creds.json', 'r') as f:
        k = json.loads(f.read())
    amz = BN.Amazon(k['amz_access'],
                    k['amz_secret'],
                    k['amz_associate_tag'],
                    MaxQPS=0.9)
    # https://github.com/lionheart/bottlenose/blob/master/README.md

    # set parameters to use function as prime or pay
    if source_name == 'amazon':
        browse_node = '2676882011'
    elif source_name == 'amazon_pay':
        browse_node = '2625373011'  # Movies & TV, the highest ancestor

    # search amz with themoviedb info
    try:
        logging.info('MAKE AMZ REQUEST')
        if media['mtype'] == 'movie':
            results = amz.ItemSearch(
                SearchIndex='Movies',
                ResponseGroup='ItemAttributes,OfferSummary',  # type of response
                BrowseNode=browse_node,  # product type of prime video
                Title=title,
                Keywords=director)
        else:
            results = amz.ItemSearch(
                SearchIndex='Movies',
                ResponseGroup='ItemAttributes,RelatedItems,OfferSummary',
                BrowseNode=browse_node,  # product type of prime video
                RelationshipType='Episode',  # necessary to get show title
                Title=title)
    except urllib.error.HTTPError as e:
        logging.error(u'AMZ API HTTP ERROR, {}: {}'.format(source_name, title))
        logging.exception(e)
        return None

    # ensure results not empty
    soup = BeautifulSoup(results, "xml")
    if int(soup.find('TotalResults').text) == 0:
        logging.info(u'AMZ API no match, {}: {}'.format(source_name, title))
        return None

    return soup
예제 #19
0
 def __init__(self,
              user_name,
              user,
              access_key,
              secret_key,
              db_file='dokusho.db'):
     self._user = user
     self._user_name = user_name
     self._amazon = bottlenose.Amazon(access_key, secret_key, Region='JP')
     self._associate_tag = config.AMAZON_ASSOCIATE_TAG
     self._db_file = db_file
예제 #20
0
 def __init__(self):
     self.__amazon = bottlenose.Amazon(
         AWSAccessKeyId=app_settings.PRICE_MONITOR_AWS_ACCESS_KEY_ID,
         AWSSecretAccessKey=app_settings.
         PRICE_MONITOR_AWS_SECRET_ACCESS_KEY,
         AssociateTag=app_settings.
         PRICE_MONITOR_AMAZON_PRODUCT_API_ASSOC_TAG,
         Region=app_settings.PRICE_MONITOR_AMAZON_PRODUCT_API_REGION,
         Parser=lambda response_text: BeautifulSoup(response_text, 'lxml'),
         ErrorHandler=ProductAdvertisingAPI.handle_error,
     )
예제 #21
0
 def __init__(self):
     """
     Initialize Amazon object
     """
     self.amazon = bottlenose.Amazon(
         environ['AWS_ACCESS_KEY_ID'],
         environ['AWS_SECRET_ACCESS_KEY'],
         environ['AWS_ASSOCIATE_TAG'],
         Parser=lambda text: BeautifulSoup(text, 'lxml'),
         MaxQPS=0.5,
         ErrorHandler=error_handler)
예제 #22
0
파일: scraper.py 프로젝트: tphinkle/shelfie
def get_amazon_object():
    '''
    Need to get an amazon object and pass it around to the
    functions that use the bottlenose module
    '''

    AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_ASSOCIATE_TAG = get_amazon_api_info(
    )
    amazon = bottlenose.Amazon(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY,
                               AWS_ASSOCIATE_TAG)
    return amazon
예제 #23
0
    def set_access_key(self, country):

        if country == "JP":
            self.ASSOCIATE_TAG = "take0e-22"
            self.ACCESS_KEY = "AKIAI5YMAQGGHZ4KOZ2A"
            self.SECRET_ACCESS_KEY = "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"
            self.country = "JP"
            self.amazon = bottlenose.Amazon(self.ACCESS_KEY,
                                            self.SECRET_ACCESS_KEY,
                                            self.ASSOCIATE_TAG,
                                            Region=self.country)

        else:
            self.ASSOCIATE_TAG = "take025-20"
            self.ACCESS_KEY = "AKIAJ5VV5S2OQBB2ZDIA"
            self.SECRET_ACCESS_KEY = "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"
            self.country = "US"
            self.amazon = bottlenose.Amazon(self.ACCESS_KEY,
                                            self.SECRET_ACCESS_KEY,
                                            self.ASSOCIATE_TAG,
                                            Region=self.country)
예제 #24
0
def get_amazon_details(url):
    """Given an Amazon URL, get title, creator, etc. from imdapi.com
    """
    matches = re.search(r'\/([A-Z0-9]{10})($|\/)', url)
    asin = matches.group(1)

    aws_key = AMZ['KEY']
    aws_secret_key = AMZ['SECRET_KEY']
    aws_associate_tag = AMZ['ASSOCIATE_TAG']

    details = {}

    amazon = bottlenose.Amazon(aws_key, aws_secret_key, aws_associate_tag)
    response = amazon.ItemLookup(ItemId=asin,
                                 ResponseGroup="Large",
                                 IdType="ASIN")

    root = objectify.fromstring(response)

    if hasattr(root.Items.Item.ItemAttributes, 'Author'):
        details['creator'] = root.Items.Item.ItemAttributes.Author
    elif hasattr(root.Items.Item.ItemAttributes, 'Artist'):
        details['creator'] = root.Items.Item.ItemAttributes.Artist
    elif hasattr(root.Items.Item.ItemAttributes, 'Director'):
        details['creator'] = root.Items.Item.ItemAttributes.Director

    if hasattr(root.Items.Item.ItemAttributes, 'Title'):
        details['title'] = root.Items.Item.ItemAttributes.Title
    if hasattr(root.Items.Item.ItemAttributes, 'ISBN'):
        details['isbn'] = root.Items.Item.ItemAttributes.ISBN.text
    if hasattr(root.Items.Item.ItemAttributes, 'NumberOfPages'):
        details[
            'measurement_page_numeric'] = root.Items.Item.ItemAttributes.NumberOfPages
    if hasattr(root.Items.Item.ItemAttributes,
               'PackageDimensions') and hasattr(
                   root.Items.Item.ItemAttributes.PackageDimensions, 'Length'):
        amz_length = int(
            root.Items.Item.ItemAttributes.PackageDimensions['Length'])
        height_in_inches = '{0:.2g}'.format((amz_length / 100.0) * 2.54)
        details['measurement_height_numeric'] = height_in_inches
    if hasattr(root.Items.Item.ItemAttributes, 'ProductGroup'):
        if root.Items.Item.ItemAttributes.ProductGroup.text == 'Music':
            details['format'] = 'Sound Recording'
        elif root.Items.Item.ItemAttributes.ProductGroup.text == 'DVD':
            details['format'] = 'Video/Film'
        else:
            details['format'] = 'book'
    if hasattr(root.Items.Item.ItemAttributes, 'PublicationDate'):
        details['pub_date'] = get_year_from_raw_date(
            root.Items.Item.ItemAttributes.PublicationDate.text)

    return details
예제 #25
0
    def __init__(self):
        try:
            keys = ('AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY',
                    'AWS_ASSOCIATE_TAG')
            aws_ids = {key: os.environ[key] for key in keys}
        except KeyError:
            print('You should set the environment variables for accessing AWS')
            sys.exit(-1)

        self.amazon = bottlenose.Amazon(
            aws_ids['AWS_ACCESS_KEY_ID'],
            aws_ids['AWS_SECRET_ACCESS_KEY'],
            aws_ids['AWS_ASSOCIATE_TAG'],
            Parser=lambda text: BeautifulSoup(text, 'xml'))
예제 #26
0
 def __init__(self):
     try:
         self.amazon = bottlenose.Amazon(
             AWSAccessKeyId=self.env.AWS_ACCESS_KEY_ID,
             AWSSecretAccessKey=self.env.AWS_SECRET_ACCESS_KEY,
             AssociateTag=self.env.AWS_ASSOCIATE_TAG,
             Parser=lambda response_text: BeautifulSoup(
                 response_text, 'lxml'))
         self.is_valid = True
     except Exception as e:
         print(e)
         print("Invalid credentials for amazon object")
         self.amazon = None
         self.is_valid = False
예제 #27
0
    def get_amazon(self, keyword):
        """
        AmazonAPI
        """
        ACCESS_KEY = "AKIAIMMBGZ2N3WPQJLRQ"
        SECRET_ACCESS_KEY = "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"
        ASSOCIATE_TAG = "sbps2017-22"


        amazon = bottlenose.Amazon(ACCESS_KEY, SECRET_ACCESS_KEY, ASSOCIATE_TAG, Region="JP")
        result = amazon.ItemSearch(Keywords=keyword, SearchIndex="All", ResponseGroup="Medium, Offers")
        soup = BeautifulSoup(result, "lxml")
        items = soup.findAll("item")

        url_list = {}
        i = 0
        for item in items:
            if item.find("points") == None:
                point = '0'
            else:
                point = item.find("points").text

            if item.find("amount") == None:
                continue
            else:
                price = item.find("amount").text
                price_point = str(int(item.find("amount").text)+int(point))

            if item.find("mediumimage") == None:
                image = ''
            else:
                image_tag = item.find("mediumimage")
                if image_tag.find("url") == None:
                    image = ''
                else:
                    image = image_tag.find("url").text


            url_list[str(i)] = { "Title":item.find("title").text,
                                 "Url":item.find("detailpageurl").text,
                                 "Price":price,
                                 "Point":point,
                                 "PricePoint":price_point,
                                 "Image": image,
                                 "APIType": 'Amazon'
                                 }
            i = i + 1

        return url_list
예제 #28
0
    def __init__(self, config):
        super(AmazonSearchEngine, self).__init__()

        self.abort = False
        self.retries = 0
        self.scanned = 0
        self.pending = []
        self.mutex = QMutex()
        self.condition = QWaitCondition()
        self.responsegroups = 'ItemAttributes,OfferFull,SalesRank,Variations'
        self.bottlenose = bottlenose.Amazon(config['access_key'],
                                            config['secret_key'],
                                            config['associate_tag'],
                                            Parser=objectify.fromstring,
                                            MaxQPS=0.9)
예제 #29
0
def do_amazon_api_call(aws_credentials_index, Action, call_args):
    time.sleep(sleep_time)

    access_key_id = os.environ.get(
        'AWS_ACCESS_KEY_ID_{}'.format(aws_credentials_index))
    secret_access_key = os.environ.get(
        'AWS_SECRET_ACCESS_KEY_{}'.format(aws_credentials_index))
    store_id = os.environ.get('AWS_STORE_ID_{}'.format(aws_credentials_index))

    amazon = bottlenose.Amazon(access_key_id, secret_access_key, store_id)

    print(', '.join([aws_credentials_index, Action, str(call_args)]))
    function = getattr(amazon, Action)
    response_data = function(**call_args).decode('utf-8')
    return response_data
예제 #30
0
def main():
    # access_key = "xxx"
    # secret_key = "xxx"
    # associate_tag = "xxx"

    amazon = bottlenose.Amazon(access_key,
                               secret_key,
                               associate_tag,
                               Region="JP",
                               ErrorHandler=error_handler)

    totalpage = get_totalpages(amazon)

    for i in range(1, int(totalpage)):
        get_result(amazon, i)
        sleep(1)