<commit_before>#!/usr/bin/env python
#-------------------------------------------------------------------------------
# Name:        amazon.py
# Purpose:     wrapper for using AWS offered by Amazon 
#
# Author(s):   <NAME>
#
# Created:     04/25/2011
# Copyright:   (c) <NAME>, <NAME>, <NAME> 2011
# License:
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#-------------------------------------------------------------------------------

from lib import ecs

# Global function calls
ecs.setLicenseKey('<KEY>')
ecs.setSecretKey('<KEY>')
ecs.setLocale('us')

def lookup_isbn(isbn):
    book = ecs.ItemSearch(isbn, IdType='ISBN', SearchIndex='Books', ResponseGroup='Large')
    return data.Textbook(book[0].DetailPageURL, 
      **{'title':book[0].Title,'author':book[0].Author,'publisher':book[0].Publisher,
      'date':book[0].PublicationDate,'imageurl':book[0].SmallImage.URL,
      'language':book[0].Languages.Language[0].Name,
      'format':book[0].Binding,'isbn':book[0].ISBN,
      'isbn13':book[0].EAN})

# amazon merchants/amazon price
# Brand New, Like New, Very Good, Good, Acceptable (possible conditions)
# New = Brand New
# Used = Very Good

def lookup_listings(isbn):
    bookList = []
    bookResults = ecs.ItemSearch(isbn, MerchantId='All', Condition='All', 
      SearchIndex='Books', ResponseGroup='Large')
    for i in bookResults[0].Offers.Offer:
        bookList.append(data.TextbookListing(i.Merchant.GlancePage, 
          **{'retailer':'Amazon', 'price':i.OfferListing.Price.FormattedPrice,
          'condition':i.OfferAttributes.Condition, 'isbn':bookResults[0].ISBN,
          'isbn13':bookResults[0].EAN}))
        

# This will make a query given:
# query = string as function of type
# Type = Author, Title, or Keyword
def search(query, Type='Title'):
    pass
    
if __name__ == "__main__":
    req = AmazonReq()
    book = req.lookupISBN("0393327795")
    for i in book:
      print i.Title<commit_msg>added condition table and fixed lookup_listings(added a return)<commit_after>#!/usr/bin/env python
#-------------------------------------------------------------------------------
# Name:        amazon.py
# Purpose:     wrapper for using AWS offered by Amazon 
#
# Author(s):   <NAME>
#
# Created:     04/25/2011
# Copyright:   (c) <NAME>, <NAME>, <NAME> 2011
# License:
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#-------------------------------------------------------------------------------

import data
from lib import ecs

# Global function calls
ecs.setLicenseKey('<KEY>')
ecs.setSecretKey('<KEY>')
ecs.setLocale('us')

# condition table
conditionTable = { "New":"Brand New", "Used":"Good"}

def lookup_isbn(isbn):
    book = ecs.ItemSearch(isbn, IdType='ISBN', SearchIndex='Books', ResponseGroup='Large')
    return data.Textbook(book[0].DetailPageURL, 
      **{'title':book[0].Title,'author':book[0].Author,'publisher':book[0].Publisher,
      'date':book[0].PublicationDate,'imageurl':book[0].SmallImage.URL,
      'language':book[0].Languages.Language[0].Name,
      'format':book[0].Binding,'isbn':book[0].ISBN,
      'isbn13':book[0].EAN})

# amazon merchants/amazon price
# Brand New, Like New, Very Good, Good, Acceptable (possible conditions)
# New = Brand New
# Used = Very Good

def lookup_listings(isbn):
    bookList = []
    bookResults = ecs.ItemSearch(isbn, MerchantId='All', Condition='All', 
      SearchIndex='Books', ResponseGroup='Large')
    for i in bookResults[0].Offers.Offer:
        bookList.append(data.TextbookListing(i.Merchant.GlancePage, 
          **{'retailer':'Amazon', 'price':i.OfferListing.Price.FormattedPrice,
          'condition':conditionTable[i.OfferAttributes.Condition], 'isbn':bookResults[0].ISBN,
          'isbn13':bookResults[0].EAN}))
    return bookList

# This will make a query given:
# query = string as function of type
# Type = Author, Title, or Keyword
def search(query, Type='Title'):
    pass
    
if __name__ == "__main__":
    req = AmazonReq()
    book = req.lookupISBN("0393327795")
    for i in book:
      print i.Title
{'fraction_non_alphanumeric': 0.19080641965524073, 'fraction_numerical': 0.017436100653853776, 'mean_word_length': 3.0223107569721117, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '222865', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1492, 'n_words': 410}