def get_ASIN(etextid): sql_query = """SELECT DISTINCT title, creator, contributor FROM book WHERE id = CONVERT( _utf8 '""" + etextid + "'USING latin1) COLLATE latin1_swedish_ci;" db = connect_to_database("amazon", "root", "gitkotwg0") #repalce with password cursor = db.cursor() cursor.execute(sql_query) results = cursor.fetchall() db.close() for title, creator, contributor in results: if contributor != 'NULL': ecs.setLicenseKey('0ZW74MMABE2VX9H26182') try: books = ecs.ItemSearch(Keywords=correct_contrib(contributor) + ' ' + title, SearchIndex='Books', Sort='relevancerank') return books[0].ASIN except KeyError: return "None" else: try: ecs.setLicenseKey('0ZW74MMABE2VX9H26182') books = ecs.ItemSearch(Keywords=title, SearchIndex='Books', Sort='relevancerank') return books[0].ASIN except KeyError: return "None" except ecs.AWSException: return "None" except TypeError: return "None"
def get_ASIN(etextid): sql_query = """SELECT DISTINCT title, creator, contributor FROM book WHERE id = '""" + etextid + "';" db = connect_to_database("amazon", "root", "gitkotwg0") #repace with password cursor = db.cursor() cursor.execute(sql_query) results = cursor.fetchall() db.close() for title, creator, contributor in results: if contributor != 'NULL': ecs.setLicenseKey('0ZW74MMABE2VX9H26182') try: books = ecs.ItemSearch(Keywords=correct_contrib(contributor) + ' ' + title, SearchIndex='Books', Sort='relevancerank') return books[0].ASIN except KeyError: print "KEYERROR" else: try: ecs.setLicenseKey('0ZW74MMABE2VX9H26182') books = ecs.ItemSearch(title, SearchIndex='Books', Sort='relevancerank') return books[0].ASIN except KeyError: return "KeyError"
def searchAmazon(self, keywords): ecs.setLicenseKey('11GY40BZY8FWYGMMVKG2') ecs.setSecretKey('4BKnT84c3U8EfpgVbTlj4+siFIQo3+TQURTHXhFx') ecs.setLocale('us') books = ecs.ItemSearch(keywords, SearchIndex='Books', ResponseGroup='Medium', AssociateTag='appinventoror-22') amazon_books = self.buildResultList(books) return amazon_books
def _query_amazon(title, author): # strips dates from author names author = re.sub('[0-9-]+', ' ', author).strip() try: res = ecs.ItemSearch(None, SearchIndex="Books", Title=title, Author=author, ResponseGroup="ItemAttributes") except KeyError, e: # Ignore nomathes error if 'ECommerceService.NoExactMatches' in str(e): return [] else: raise
def amazon_by_keyword(keyword): """ Use the ecs library to search for books by keyword. Args: keyword: A string of keyword(s) to search for. Returns: A list of three item lists. Each sublist represents a result and includes the book title, its lowest found price and its ASIN number. """ ecs.setLicenseKey(license_key) ecs.setSecretKey(secret_key) ecs.setLocale('us') books = ecs.ItemSearch(keyword, SearchIndex='Books', ResponseGroup='Medium') return format_output(books)
def query_amazon(self, title, author): """Queries amazon.com using its API to find all the books matching given title and author. """ # strips dates from author names author = re.sub('[0-9-]+', ' ', author).strip() title = title.encode('utf-8').replace("/", " ") author = author.encode('utf-8').replace("/", " ") try: res = ecs.ItemSearch(None, SearchIndex="Books", Title=title, Author=author, ResponseGroup="Large") except KeyError, e: # Ignore nomathes error if 'ECommerceService.NoExactMatches' in str(e): return [] else: raise