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,29 +47,38 @@ class AmazonKindleStore(StorePlugin):
if 'kindle' not in type.lower():
continue
title = ''.join(data.xpath('div[@class="productTitle"]/a/text()'))
author = ''.join(data.xpath('div[@class="productTitle"]/span[@class="ptBrand"]/text()'))
author = author.split('by')[-1]
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)
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()'))
author = ''.join(data.xpath('div[@class="productTitle"]/span[@class="ptBrand"]/text()'))
author = author.split('by')[-1]
price = ''.join(data.xpath('div[@class="newPrice"]/span/text()'))
counter -= 1
s = SearchResult()
s.cover_url = ''
s.title = title.strip()
s.author = author.strip()
s.price = price.strip()
s.detail_item = '/detail/' + asin.strip()
yield s
counter -= 1
s = SearchResult()
s.cover_url = cover_url
s.title = title.strip()
s.author = author.strip()
s.price = price.strip()
s.detail_item = '/detail/' + asin.strip()
yield s

View File

@ -52,7 +52,7 @@ class GutenbergStore(StorePlugin):
id = url.split('/')[-1]
heading = ''.join(url_a.xpath('text()'))
title, _, author = heading.partition('by')
title, _, author = heading.partition('by ')
author = author.split('-')[0]
price = '$0.00'

View File

@ -56,7 +56,7 @@ class ManyBooksStore(StorePlugin):
id = id.strip()
heading = ''.join(url_a.xpath('text()'))
title, _, author = heading.partition('by')
title, _, author = heading.partition('by ')
author = author.split('-')[0]
price = '$0.00'

View File

@ -4,6 +4,7 @@ __license__ = 'GPL 3'
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
import random
import re
import urllib2
from contextlib import closing
@ -22,7 +23,11 @@ class SmashwordsStore(StorePlugin):
def open(self, gui, parent=None, detail_item=None):
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.set_tags(self.name + ',' + _('store'))
d = d.exec_()