Fix smashworks store not showing any results.

This commit is contained in:
John Schember 2014-02-23 20:37:28 -05:00
parent 18871b185d
commit 8782ec322a

View File

@ -54,36 +54,32 @@ class SmashwordsStore(BasicStoreConfig, StorePlugin):
counter = max_results counter = max_results
with closing(br.open(url, timeout=timeout)) as f: with closing(br.open(url, timeout=timeout)) as f:
doc = html.fromstring(f.read()) doc = html.fromstring(f.read())
for data in doc.xpath('//div[@id="pageCenterContent"]//div[@class="bookCoverImg"]'): for data in doc.xpath('//div[@id="pageCenterContent"]//div[@class="library-book"]'):
if counter <= 0: if counter <= 0:
break break
data = html.fromstring(html.tostring(data)) data = html.fromstring(html.tostring(data))
id = None id = None
id_a = data.xpath('//a[@class="bookTitle"]') id_a = ''.join(data.xpath('//a[contains(@class, "library-title")]/@href'))
if id_a: if id_a:
id = id_a[0].get('href', None) id = id_a.split('/')[-1]
if id:
id = id.split('/')[-1]
if not id: if not id:
continue continue
cover_url = '' cover_url = ''.join(data.xpath('//img[contains(@class, "book-list-image")]/@src'))
c_url = data.get('style', None)
if c_url:
mo = re.search(r'http://[^\'"]+', c_url)
if mo:
cover_url = mo.group()
title = ''.join(data.xpath('//a[@class="bookTitle"]/text()')) title = ''.join(data.xpath('.//a[contains(@class, "library-title")]/text()'))
subnote = ''.join(data.xpath('//span[@class="subnote"]/text()')) author = ''.join(data.xpath('.//div[@class="subnote"]//a[1]//text()'))
author = ''.join(data.xpath('//span[@class="subnote"]//a[1]//text()'))
if '$' in subnote: price = ''.join(data.xpath('.//div[@class="subnote"]//text()'))
price = subnote.partition('$')[2] if 'Price:' in price:
price = price.split(u'\xa0')[0] try:
price = '$' + price price = price.partition('Price:')[2]
else: price = re.sub('\s', ' ', price).strip()
price = '$0.00' price = price.split(' ')[0]
price = price.strip()
except:
price = 'Unknown'
counter -= 1 counter -= 1
@ -103,5 +99,5 @@ class SmashwordsStore(BasicStoreConfig, StorePlugin):
br = browser() br = browser()
with closing(br.open(url + search_result.detail_item, timeout=timeout)) as nf: with closing(br.open(url + search_result.detail_item, timeout=timeout)) as nf:
idata = html.fromstring(nf.read()) idata = html.fromstring(nf.read())
search_result.formats = ', '.join(list(set(idata.xpath('//td//b//text()')))) search_result.formats = ', '.join(list(set(idata.xpath('//p//abbr//text()'))))
return True return True