Merge lp:~user-none/calibre/store into lp:calibre

Proposed by John Schember
Status: Merged
Merged at revision: 12164
Proposed branch: lp:~user-none/calibre/store
Merge into: lp:calibre
Diff against target: 113 lines (+53/-23)
2 files modified
src/calibre/gui2/store/stores/amazon_plugin.py (+0/-2)
src/calibre/gui2/store/stores/diesel_ebooks_plugin.py (+53/-21)
To merge this branch: bzr merge lp:~user-none/calibre/store
Reviewer Review Type Date Requested Status
Kovid Goyal Pending
Review via email: mp+105563@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/calibre/gui2/store/stores/amazon_plugin.py'
2--- src/calibre/gui2/store/stores/amazon_plugin.py 2012-04-29 15:46:14 +0000
3+++ src/calibre/gui2/store/stores/amazon_plugin.py 2012-05-12 18:28:18 +0000
4@@ -156,8 +156,6 @@
5 cover_xpath = './/div[@class="productImage"]//img/@src'
6 title_xpath = './/div[@class="productTitle"]/a/text()'
7 price_xpath = './/div[@class="newPrice"]//span//text()'
8-
9-
10
11 for data in doc.xpath(data_xpath):
12 if counter <= 0:
13
14=== modified file 'src/calibre/gui2/store/stores/diesel_ebooks_plugin.py'
15--- src/calibre/gui2/store/stores/diesel_ebooks_plugin.py 2012-05-12 17:38:06 +0000
16+++ src/calibre/gui2/store/stores/diesel_ebooks_plugin.py 2012-05-12 18:28:18 +0000
17@@ -7,6 +7,7 @@
18 __docformat__ = 'restructuredtext en'
19
20 import random
21+import re
22 import urllib
23 from contextlib import closing
24
25@@ -52,32 +53,27 @@
26 counter = max_results
27 with closing(br.open(url, timeout=timeout)) as f:
28 doc = html.fromstring(f.read())
29- for data in doc.xpath('//div[contains(@class, "item")]'):
30- if counter <= 0:
31- break
32-
33- id = ''.join(data.xpath('div[@class="cover"]/a/@href'))
34- if not id or '/item/' not in id:
35- continue
36-
37- cover_url = ''.join(data.xpath('div[@class="cover"]//img/@src'))
38-
39- title = ''.join(data.xpath('.//div[@class="content"]//h2/a/text()'))
40- author = ''.join(data.xpath('.//div[@class="content"]/span//a/text()'))
41- price = ''
42- price_elem = data.xpath('.//div[@class="price_fat"]//h1/text()')
43- if price_elem:
44- price = price_elem[0]
45-
46- formats = ', '.join(data.xpath('.//div[@class="book-info"]//text()')).strip()
47+
48+ if doc.xpath('not(boolean(//select[contains(@id, "selection")]))'):
49+ id = ''.join(doc.xpath('//div[@class="price_fat"]//a/@href'))
50+ mo = re.search('(?<=id=).+?(?=&)', id)
51+ if not mo:
52+ yield None
53+ id = mo.group()
54+
55+ cover_url = ''.join(doc.xpath('//div[@class="cover"]/a/@href'))
56+
57+ title = ''.join(doc.xpath('//div[@class="desc_fat"]//h1/text()'))
58+ author = ''.join(doc.xpath('//div[@class="desc_fat"]//span[@itemprop="author"]/text()'))
59+ price = ''.join(doc.xpath('//div[@class="price_fat"]//h1/text()'))
60+
61+ formats = ', '.join(doc.xpath('//div[@class="desc_fat"]//p[contains(text(), "Format")]/text()'))
62 a, b, formats = formats.partition('Format:')
63+
64 drm = SearchResult.DRM_LOCKED
65 if 'drm free' in formats.lower():
66 drm = SearchResult.DRM_UNLOCKED
67
68-
69- counter -= 1
70-
71 s = SearchResult()
72 s.cover_url = cover_url
73 s.title = title.strip()
74@@ -88,3 +84,39 @@
75 s.drm = drm
76
77 yield s
78+ else:
79+ for data in doc.xpath('//div[contains(@class, "item")]'):
80+ if counter <= 0:
81+ break
82+
83+ id = ''.join(data.xpath('div[@class="cover"]/a/@href'))
84+ if not id or '/item/' not in id:
85+ continue
86+
87+ cover_url = ''.join(data.xpath('div[@class="cover"]//img/@src'))
88+
89+ title = ''.join(data.xpath('.//div[@class="content"]//h2/a/text()'))
90+ author = ''.join(data.xpath('.//div[@class="content"]/span//a/text()'))
91+ price = ''
92+ price_elem = data.xpath('.//div[@class="price_fat"]//h1/text()')
93+ if price_elem:
94+ price = price_elem[0]
95+
96+ formats = ', '.join(data.xpath('.//div[@class="book-info"]//text()')).strip()
97+ a, b, formats = formats.partition('Format:')
98+ drm = SearchResult.DRM_LOCKED
99+ if 'drm free' in formats.lower():
100+ drm = SearchResult.DRM_UNLOCKED
101+
102+ counter -= 1
103+
104+ s = SearchResult()
105+ s.cover_url = cover_url
106+ s.title = title.strip()
107+ s.author = author.strip()
108+ s.price = price.strip()
109+ s.detail_item = id.strip()
110+ s.formats = formats
111+ s.drm = drm
112+
113+ yield s

Subscribers

People subscribed via source and target branches