Ejemplo n.º 1
0
def get_page(domain, asin, locale):

    ecs.setLocale(locale)
    try:
        pages = ecs.ItemLookup(asin, ResponseGroup="Medium")
    except ecs.InvalidParameterValue, e:
        raise UserException, str(e)
Ejemplo n.º 2
0
 def testVariations(self):
     shirts = ecs.ItemLookup('B000EI6M5A', ResponseGroup='Variations')
     self.assertEqual(len(shirts), 1)
     shirt = shirts[0]
     self.assertEqual(shirt.Variations[0].ASIN, 'B000EG9PLU')
     self.assertEqual(shirt.Variations[5].ASIN, 'B000EG5DUM')
     self.assertEqual(shirt.VariationSummary.HighestPrice.Amount, '699')
     self.assertEqual(shirt.VariationSummary.LowestPrice.Amount, '699')
Ejemplo n.º 3
0
    def testSubjects(self):
        books = ecs.ItemLookup(self.ItemId, ResponseGroup='Subjects')
        self.assertEqual(len(books), 1)
        book = books[0]

        subs = book.Subjects
        self.assertEqual(len(subs), 10)
        self.assertEqual(subs[0], 'Programming languages')
        self.assertEqual(subs[2], 'Computers')
Ejemplo n.º 4
0
    def testReviews(self):
        books = ecs.ItemLookup(self.ItemId, ResponseGroup='Reviews')
        self.assertEqual(len(books), 1)
        book = books[0]
        self.assertEqual(len(book.CustomerReviews), 68)

        # arbitary reviewer
        self.assertEqual(book.CustomerReviews[34].Reviewer.Name, 'Sameer')
        self.assertEqual(book.CustomerReviews[12].Summary,
                         'An Essential Python Book for Python Programmers')
Ejemplo n.º 5
0
    def testOfferFull(self):
        txs = ecs.ItemLookup('B000BI7NHY',
                             MerchantId='All',
                             Condition='All',
                             ResponseGroup='OfferFull')
        self.assertEqual(len(txs), 1)
        tx = txs[0]

        # arbitary seller
        self.assertNotEqual(tx.Offers[23].Merchant.MerchantId, None)
Ejemplo n.º 6
0
    def testSmall(self):
        books = ecs.ItemLookup(self.ItemId, ResponseGroup='Request,Small')
        self.assertEqual(len(books), 1)
        book = books[0]
        self.assertNotEqual(book, None)

        self.assertEqual(book.ASIN, '0596009259')
        self.assertEqual(book.Title, 'Programming Python')
        self.assertEqual(book.Manufacturer, "O'Reilly Media, Inc.")
        self.assertEqual(book.ProductGroup, 'Book')
        self.assertEqual(book.Author, 'Mark Lutz')
Ejemplo n.º 7
0
 def testTracks(self):
     cds = ecs.ItemLookup('B0000042H4', ResponseGroup='Tracks')
     self.assertEqual(len(cds), 1)
     cd = cds[0].Tracks
     self.assertEqual(len(cd.Disc), 14)
     self.assertEqual(
         cd.Disc[13].Track[5],
         'Gotterdammerung: Dritter Aufzug, Zweite Szene: Hoiho!')
     self.assertEqual(
         cd.Disc[4].Track[3],
         'Die Walkure: Zweiter Aufzug, Funfte Szene: Zauberfest bezahmt ein Schlaf der Holden Schmerz und Harm'
     )
Ejemplo n.º 8
0
    def testSimilarities(self):
        books = ecs.ItemLookup(self.ItemId, ResponseGroup='Similarities')
        self.assertEqual(len(books), 1)
        book = books[0]

        sim = book.SimilarProducts
        self.assertEqual(len(sim), 5)
        self.assertEqual(sim[0].Title, 'Learning Python, Second Edition')
        self.assertEqual(sim[1].Title, 'Python Cookbook')
        self.assertEqual(
            sim[3].Title,
            "Python Essential Reference (3rd Edition) (Developer's Library)")
Ejemplo n.º 9
0
    def testBrowseNodes(self):
        books = ecs.ItemLookup(self.ItemId, ResponseGroup='BrowseNodes')
        self.assertEqual(len(books), 1)
        book = books[0]
        self.assertEqual(len(book.BrowseNodes), 11)
        bn = book.BrowseNodes[0]
        # iterate all the ancestors
        names = ('Perl', 'Programming', "O'Reilly", 'By Publisher')
        for x in names:
            self.assertEqual(bn.Name, x)
            bn = bn.Ancestors[0]

        self.assertEqual(bn.Name, 'Books')
Ejemplo n.º 10
0
    def testMedium(self):
        books = ecs.ItemLookup(self.ItemId, ResponseGroup='Request,Medium')
        self.assertEqual(len(books), 1)
        book = books[0]

        self.assertEqual(book.ASIN, '0596009259')
        self.assertEqual(book.Title, 'Programming Python')
        self.assertEqual(book.Manufacturer, "O'Reilly Media, Inc.")
        self.assertEqual(book.ProductGroup, 'Book')
        self.assertEqual(book.Author, 'Mark Lutz')

        # EditorialReview
        self.assertEqual(len(book.EditorialReviews), 2)
        self.assertEqual(book.EditorialReviews[0].Source, 'Amazon.com')
        self.assertEqual(book.EditorialReviews[1].Source, 'Book Description')

        # Images
        self.assertEqual(len(book.ImageSets), 1)
        self.assertEqual(book.ImageSets[0].LargeImage.Height, '500')
        self.assertEqual(book.ImageSets[0].MediumImage.Height, '160')
        self.assertEqual(book.ImageSets[0].SmallImage.Height, '75')

        # ItemAttributes
        pass

        # ItemIds
        pass

        # OfferSummary
        self.assertNotEqual(book.OfferSummary.TotalNew, '0')
        self.assertIsInteger(
            book.OfferSummary.LowestNewPrice.Amount,
            'book.OfferSummary.LowestNewPrice.Amount is not integer')

        # SalesRank
        self.assertNotEqual(book.SalesRank, '0')
Ejemplo n.º 11
0
def fetch(page, asin, locale):

    field_map = [
        (['Title'], 'title'),
        (['ISBN'], 'isbn'),
        (['Publisher'], 'publisher'),
        (['Edition'], 'edition'),
        (['Binding'], 'how_published'),
    ]

    amazon_type = extract(page, ["ProductGroup"])
    if amazon_type != "Book":
        raise UserException(
            "This item on Amazon does not appear to be a book. It looks like a %s"
            % amazon_type)
    else:
        yield ("type", "BOOK")

    for (path, our_name) in field_map:
        val = extract(page, path)
        if val:
            yield (our_name, tidy(val))

    date = extract(page, ['PublicationDate'])
    if date:
        try:
            (year, month, day) = date.split("-")
            yield ("year", year)
            yield ("month", month)
            yield ("day", day)
        except ValueError:
            pass

    authors = extract(page, ['Author'])
    if authors:
        if isinstance(authors, basestring):
            yield ("author", tidy(authors))
        else:
            for author in authors:
                yield ("author", tidy(author))

    # We put the images in as linkouts. CiteULike uses these
    # internally to show cover images.
    for (theirs, ours) in [('SmallImage', 'IMGS'), ('MediumImage', 'IMGM'),
                           ('LargeImage', 'IMGL')]:
        path = [theirs, "URL"]
        img_url = extract(page, path)
        if img_url:
            yield ("linkout", "\t".join([ours, "", img_url, "", ""]))

    isbn = extract(page, ['ISBN'])
    if isbn:
        yield ("linkout", "\t".join(["ISBN", "", isbn, "", ""]))

    title = extract(page, ["Title"])
    if not title and isbn:
        yield ("status", "redirect\thttp://www.worldcat.org/isbn/%s" % isbn)
        sys.exit(0)

    def get_abstract(n):
        abstract = extract(n,
                           ['EditorialReviews', 'EditorialReview', 'Content'])
        if abstract:
            return tidy(html2text(abstract))

    seen_abstract = False
    if not seen_abstract:
        abstract = get_abstract(page)
        if abstract:
            yield ("abstract", abstract)
            seen_abstract = True

    # Linkouts to the ASINS

    yield ("linkout", "\t".join(["AZ-%s" % locale.upper(), "", asin, "", ""]))

    # Different amazons may know this product by a different
    # ASIN. Trawl through all of them and see who has this one.
    for other_locale in ["us", "uk", "de", "jp", "fr", "ca"]:

        if other_locale == locale:
            continue
        ecs.setLocale(other_locale)
        try:
            pages = ecs.ItemLookup(asin, ResponseGroup="Medium")
        except ecs.InvalidParameterValue:
            continue

        page = pages
        if not seen_abstract:
            abstract = get_abstract(page)
            if abstract:
                yield ("abstract", abstract)
                seen_abstract = True

        yield ("linkout",
               "\t".join(["AZ-%s" % other_locale.upper(), "", asin, "", ""]))
Ejemplo n.º 12
0
    for searchField in fields:

        if (searchLocale != "" and searchField != ""):
            collection = doc.createElement("List")
            collection.setAttribute("name", "Amazon Import")
            root.appendChild(collection)

            pythonBooks = None

            if searchField == "authors":
                pythonBooks = ecs.ItemSearch('',
                                             Author=query,
                                             SearchIndex=searchMode)
            elif searchField == "asin":
                pythonBooks = ecs.ItemLookup(query)
            else:
                pythonBooks = ecs.ItemSearch('',
                                             Title=query,
                                             SearchIndex=searchMode)

            for book in pythonBooks:
                try:
                    bookElement = doc.createElement("Book")
                    # book = ecs.ItemLookup(book.ASIN)[0]

                    bookElement.setAttribute("title", book.Title)

                    print(book.Title + ": " + str(dir(book)))

                    for key in fieldMap.keys():
Ejemplo n.º 13
0
 def testAccessories(self):
     # We have to use Palm Tungsten X
     txs = ecs.ItemLookup('B000BI7NHY', ResponseGroup='Accessories')
     self.assertEqual(len(txs), 1)
     tx = txs[0]
     self.assertEqual(tx.Accessories[4].ASIN, 'B00006BB9E')
Ejemplo n.º 14
0
 def testVariationMinimum(self):
     shirts = ecs.ItemLookup('B000EI6M5A', ResponseGroup='VariationMinimum')
     self.assertEqual(len(shirts), 1)
     shirt = shirts[0]
     self.assertEqual(shirt.Variations[0].ASIN, 'B000EG9PLU')
     self.assertEqual(shirt.Variations[5].ASIN, 'B000EG5DUM')