Store: Fix OReilly.

This commit is contained in:
John Schember 2012-02-18 13:25:37 -05:00
parent 1bcae76a61
commit bb93eecbe7

View File

@ -26,9 +26,6 @@ class OReillyStore(BasicStoreConfig, StorePlugin):
def open(self, parent=None, detail_item=None, external=False): def open(self, parent=None, detail_item=None, external=False):
url = 'http://oreilly.com/ebooks/' url = 'http://oreilly.com/ebooks/'
if detail_item:
detail_item = 'https://epoch.oreilly.com/shop/cart.orm?prod=%s.EBOOK&p=CALIBRE' % detail_item
if external or self.config.get('open_external', False): if external or self.config.get('open_external', False):
open_url(QUrl(url_slash_cleaner(detail_item if detail_item else url))) open_url(QUrl(url_slash_cleaner(detail_item if detail_item else url)))
else: else:
@ -49,11 +46,11 @@ class OReillyStore(BasicStoreConfig, StorePlugin):
if counter <= 0: if counter <= 0:
break break
full_id = ''.join(data.xpath('./div[@class="book_text"]//p[@class="title"]/a/@href')) ebook = ' '.join(data.xpath('.//p[@class="note"]/text()'))
mo = re.search('\d+', full_id) if 'ebook' not in ebook.lower():
if not mo:
continue continue
id = mo.group()
id = ''.join(data.xpath('./div[@class="book_text"]//p[@class="title"]/a/@href'))
cover_url = ''.join(data.xpath('./a/img[1]/@src')) cover_url = ''.join(data.xpath('./a/img[1]/@src'))
@ -62,16 +59,14 @@ class OReillyStore(BasicStoreConfig, StorePlugin):
author = author.split('By ')[-1].strip() author = author.split('By ')[-1].strip()
# Get the detail here because we need to get the ebook id for the detail_item. # Get the detail here because we need to get the ebook id for the detail_item.
with closing(br.open(full_id, timeout=timeout)) as nf: with closing(br.open(id, timeout=timeout)) as nf:
idoc = html.fromstring(nf.read()) idoc = html.fromstring(nf.read())
price = ''.join(idoc.xpath('(//span[@class="price"])[1]/span//text()')) for td in idoc.xpath('//td[@class="optionsTd"]'):
formats = ', '.join(idoc.xpath('//div[@class="ebook_formats"]//a/text()')) if 'ebook' in ''.join(td.xpath('.//text()')).lower():
price = ''.join(td.xpath('.//span[@class="price"]/text()')).strip()
eid = ''.join(idoc.xpath('(//a[@class="product_buy_link" and contains(@href, ".EBOOK")])[1]/@href')).strip() formats = ''.join(td.xpath('.//a[@id="availableFormats"]/text()')).strip()
mo = re.search('\d+', eid) break
if mo:
id = mo.group()
counter -= 1 counter -= 1