~ubuntu-branches/debian/wheezy/calibre/wheezy

« back to all changes in this revision

Viewing changes to src/calibre/gui2/store/stores/amazon_uk_plugin.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-10-04 10:29:28 UTC
  • mfrom: (29.3.5 sid)
  • Revision ID: james.westby@ubuntu.com-20111004102928-lbwg8cyjscq1tiz7
Tags: 0.8.21+dfsg-1
* New upstream release. (Closes: #642517)
* debian/control: Revert accidental X-Ubuntu-Original-Maintainer change.
  (Closes: #644029)

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
            doc = html.fromstring(f.read())
43
43
 
44
44
            # Amazon has two results pages.
45
 
            is_shot = doc.xpath('boolean(//div[@id="shotgunMainResults"])')
46
 
            # Horizontal grid of books.
47
 
            if is_shot:
48
 
                data_xpath = '//div[contains(@class, "result")]'
49
 
                cover_xpath = './/div[@class="productTitle"]//img/@src'
50
 
            # Vertical list of books.
51
 
            else:
52
 
                data_xpath = '//div[contains(@class, "product")]'
53
 
                cover_xpath = './div[@class="productImage"]/a/img/@src'
 
45
            # 20110725: seems that is_shot is gone.
 
46
#            is_shot = doc.xpath('boolean(//div[@id="shotgunMainResults"])')
 
47
#            # Horizontal grid of books.
 
48
#            if is_shot:
 
49
#                data_xpath = '//div[contains(@class, "result")]'
 
50
#                format_xpath = './/div[@class="productTitle"]/text()'
 
51
#                cover_xpath = './/div[@class="productTitle"]//img/@src'
 
52
#            # Vertical list of books.
 
53
#            else:
 
54
            data_xpath = '//div[contains(@class, "result") and contains(@class, "product")]'
 
55
            format_xpath = './/span[@class="format"]/text()'
 
56
            cover_xpath = './/img[@class="productImage"]/@src'
 
57
# end is_shot else
54
58
 
55
59
            for data in doc.xpath(data_xpath):
56
60
                if counter <= 0:
57
61
                    break
58
62
 
 
63
                # Even though we are searching digital-text only Amazon will still
 
64
                # put in results for non Kindle books (author pages). So we need
 
65
                # to explicitly check if the item is a Kindle book and ignore it
 
66
                # if it isn't.
 
67
                format = ''.join(data.xpath(format_xpath))
 
68
                if 'kindle' not in format.lower():
 
69
                    continue
 
70
 
59
71
                # We must have an asin otherwise we can't easily reference the
60
72
                # book later.
61
 
                asin = ''.join(data.xpath('./@name'))
62
 
                if not asin:
63
 
                    continue
 
73
                asin = ''.join(data.xpath("@name"))
 
74
 
64
75
                cover_url = ''.join(data.xpath(cover_xpath))
65
76
 
66
 
                title = ''.join(data.xpath('.//div[@class="productTitle"]/a/text()'))
 
77
                title = ''.join(data.xpath('.//div[@class="title"]/a/text()'))
67
78
                price = ''.join(data.xpath('.//div[@class="newPrice"]/span/text()'))
68
79
 
 
80
#                if is_shot:
 
81
#                    author = format.split(' von ')[-1]
 
82
#                else:
 
83
                author = ''.join(data.xpath('.//div[@class="title"]/span[@class="ptBrand"]/text()'))
 
84
                author = author.split('by ')[-1]
 
85
 
69
86
                counter -= 1
70
87
 
71
88
                s = SearchResult()
72
89
                s.cover_url = cover_url.strip()
73
90
                s.title = title.strip()
 
91
                s.author = author.strip()
74
92
                s.price = price.strip()
75
93
                s.detail_item = asin.strip()
76
 
                s.formats = ''
77
 
 
78
 
                if is_shot:
79
 
                    # Amazon UK does not include the author on the grid layout
80
 
                    s.author = ''
81
 
                    self.get_details(s, timeout)
82
 
                    if s.formats != 'Kindle':
83
 
                        continue
84
 
                else:
85
 
                    author = ''.join(data.xpath('.//div[@class="productTitle"]/span[@class="ptBrand"]/text()'))
86
 
                    s.author = author.split(' by ')[-1].strip()
87
 
                    s.formats = 'Kindle'
 
94
                s.formats = 'Kindle'
88
95
 
89
96
                yield s
90
97