Get Books: Diesel, fix results not showing when only a single match is found

This commit is contained in:
Kovid Goyal 2012-05-13 07:07:06 +05:30
commit e638c9f3f3
2 changed files with 49 additions and 19 deletions

View File

@ -157,8 +157,6 @@ class AmazonKindleStore(StorePlugin):
title_xpath = './/div[@class="productTitle"]/a/text()'
price_xpath = './/div[@class="newPrice"]//span//text()'
for data in doc.xpath(data_xpath):
if counter <= 0:
break

View File

@ -7,6 +7,7 @@ __copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
import random
import re
import urllib
from contextlib import closing
@ -52,6 +53,38 @@ class DieselEbooksStore(BasicStoreConfig, StorePlugin):
counter = max_results
with closing(br.open(url, timeout=timeout)) as f:
doc = html.fromstring(f.read())
if doc.xpath('not(boolean(//select[contains(@id, "selection")]))'):
id = ''.join(doc.xpath('//div[@class="price_fat"]//a/@href'))
mo = re.search('(?<=id=).+?(?=&)', id)
if not mo:
yield None
id = mo.group()
cover_url = ''.join(doc.xpath('//div[@class="cover"]/a/@href'))
title = ''.join(doc.xpath('//div[@class="desc_fat"]//h1/text()'))
author = ''.join(doc.xpath('//div[@class="desc_fat"]//span[@itemprop="author"]/text()'))
price = ''.join(doc.xpath('//div[@class="price_fat"]//h1/text()'))
formats = ', '.join(doc.xpath('//div[@class="desc_fat"]//p[contains(text(), "Format")]/text()'))
a, b, formats = formats.partition('Format:')
drm = SearchResult.DRM_LOCKED
if 'drm free' in formats.lower():
drm = SearchResult.DRM_UNLOCKED
s = SearchResult()
s.cover_url = cover_url
s.title = title.strip()
s.author = author.strip()
s.price = price.strip()
s.detail_item = id.strip()
s.formats = formats
s.drm = drm
yield s
else:
for data in doc.xpath('//div[contains(@class, "item")]'):
if counter <= 0:
break
@ -75,7 +108,6 @@ class DieselEbooksStore(BasicStoreConfig, StorePlugin):
if 'drm free' in formats.lower():
drm = SearchResult.DRM_UNLOCKED
counter -= 1
s = SearchResult()