Amazon Kindle store return cover_url

This commit is contained in:
John Schember 2011-02-27 16:27:38 -05:00
parent 1633c8f8d0
commit 81b734c5c1
4 changed files with 36 additions and 22 deletions

View File

@ -47,26 +47,35 @@ class AmazonKindleStore(StorePlugin):
if 'kindle' not in type.lower(): if 'kindle' not in type.lower():
continue continue
# We must have an asin otherwise we can't easily reference the
# book later.
asin_href = None
asin_a = data.xpath('div[@class="productTitle"]/a[1]')
if asin_a:
asin_href = asin_a[0].get('href', '')
m = re.search(r'/dp/(?P<asin>.+?)(/|$)', asin_href)
if m:
asin = m.group('asin')
else:
continue
else:
continue
cover_url = ''
if asin_href:
cover_img = data.xpath('//div[@class="productImage"]/a[@href="%s"]/img/@src' % asin_href)
if cover_img:
cover_url = cover_img[0]
title = ''.join(data.xpath('div[@class="productTitle"]/a/text()')) title = ''.join(data.xpath('div[@class="productTitle"]/a/text()'))
author = ''.join(data.xpath('div[@class="productTitle"]/span[@class="ptBrand"]/text()')) author = ''.join(data.xpath('div[@class="productTitle"]/span[@class="ptBrand"]/text()'))
author = author.split('by')[-1] author = author.split('by')[-1]
price = ''.join(data.xpath('div[@class="newPrice"]/span/text()')) price = ''.join(data.xpath('div[@class="newPrice"]/span/text()'))
# We must have an asin otherwise we can't easily reference the
# book later.
asin = data.xpath('div[@class="productTitle"]/a[1]')
if asin:
asin = asin[0].get('href', '')
m = re.search(r'/dp/(?P<asin>.+?)(/|$)', asin)
if m:
asin = m.group('asin')
else:
continue
counter -= 1 counter -= 1
s = SearchResult() s = SearchResult()
s.cover_url = '' s.cover_url = cover_url
s.title = title.strip() s.title = title.strip()
s.author = author.strip() s.author = author.strip()
s.price = price.strip() s.price = price.strip()

View File

@ -4,6 +4,7 @@ __license__ = 'GPL 3'
__copyright__ = '2011, John Schember <john@nachtimwald.com>' __copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import random
import re import re
import urllib2 import urllib2
from contextlib import closing from contextlib import closing
@ -22,7 +23,11 @@ class SmashwordsStore(StorePlugin):
def open(self, gui, parent=None, detail_item=None): def open(self, gui, parent=None, detail_item=None):
from calibre.gui2.store.web_store_dialog import WebStoreDialog from calibre.gui2.store.web_store_dialog import WebStoreDialog
d = WebStoreDialog(gui, 'http://www.smashwords.com/?ref=usernone', parent, detail_item) aff_id = 'usernone'
# Use Kovid's affiliate id 30% of the time.
if random.randint(1, 10) in (1, 2, 3):
aff_id = 'kovidgoyal'
d = WebStoreDialog(gui, 'http://www.smashwords.com/?ref=%s' % aff_id, parent, detail_item)
d.setWindowTitle(self.name) d.setWindowTitle(self.name)
d.set_tags(self.name + ',' + _('store')) d.set_tags(self.name + ',' + _('store'))
d = d.exec_() d = d.exec_()