From 6c224d75cf2a67e53fbc3acdcec663778328a3ed Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 20 Feb 2012 10:03:27 +0530 Subject: [PATCH] ... --- src/calibre/gui2/store/stores/oreilly_plugin.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/calibre/gui2/store/stores/oreilly_plugin.py b/src/calibre/gui2/store/stores/oreilly_plugin.py index 4ec25ef5f4..e45c072eea 100644 --- a/src/calibre/gui2/store/stores/oreilly_plugin.py +++ b/src/calibre/gui2/store/stores/oreilly_plugin.py @@ -6,7 +6,6 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -import re import urllib from contextlib import closing @@ -36,9 +35,9 @@ class OReillyStore(BasicStoreConfig, StorePlugin): def search(self, query, max_results=10, timeout=60): url = 'http://search.oreilly.com/?t1=Books&t2=Format&t3=Ebook&q=' + urllib.quote_plus(query) - + br = browser() - + counter = max_results with closing(br.open(url, timeout=timeout)) as f: doc = html.fromstring(f.read()) @@ -49,7 +48,7 @@ class OReillyStore(BasicStoreConfig, StorePlugin): ebook = ' '.join(data.xpath('.//p[@class="note"]/text()')) if 'ebook' not in ebook.lower(): continue - + id = ''.join(data.xpath('./div[@class="book_text"]//p[@class="title"]/a/@href')) cover_url = ''.join(data.xpath('./a/img[1]/@src')) @@ -61,7 +60,7 @@ class OReillyStore(BasicStoreConfig, StorePlugin): # Get the detail here because we need to get the ebook id for the detail_item. with closing(br.open(id, timeout=timeout)) as nf: idoc = html.fromstring(nf.read()) - + for td in idoc.xpath('//td[@class="optionsTd"]'): if 'ebook' in ''.join(td.xpath('.//text()')).lower(): price = ''.join(td.xpath('.//span[@class="price"]/text()')).strip() @@ -69,7 +68,7 @@ class OReillyStore(BasicStoreConfig, StorePlugin): break counter -= 1 - + s = SearchResult() s.cover_url = cover_url.strip() s.title = title.strip() @@ -78,5 +77,5 @@ class OReillyStore(BasicStoreConfig, StorePlugin): s.price = price.strip() s.drm = SearchResult.DRM_UNLOCKED s.formats = formats.upper() - + yield s