Basic Feedbooks store plugin.

This commit is contained in:
John Schember 2011-02-26 13:29:52 -05:00
parent 210b7e48c0
commit 93c2231f26
5 changed files with 72 additions and 5 deletions

View File

@ -1043,8 +1043,9 @@ plugins += [GoogleBooks]
# Store plugins {{{
from calibre.gui2.store.amazon_plugin import AmazonKindleStore
from calibre.gui2.store.gutenberg_plugin import GutenbergStore
from calibre.gui2.store.feedbooks_plugin import FeedbooksStore
from calibre.gui2.store.manybooks_plugin import ManyBooksStore
plugins += [AmazonKindleStore, GutenbergStore, ManyBooksStore]
plugins += [AmazonKindleStore, GutenbergStore, FeedbooksStore, ManyBooksStore]
# }}}

View File

@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
__license__ = 'GPL 3'
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
import urllib2
from contextlib import closing
from lxml import html
from calibre import browser
from calibre.customize import StorePlugin
class FeedbooksStore(StorePlugin):
name = 'Feedbooks'
description = _('Read anywhere.')
def open(self, gui, parent=None, start_item=None):
from calibre.gui2.store.web_store_dialog import WebStoreDialog
d = WebStoreDialog(gui, 'http://m.feedbooks.com/', parent, start_item)
d.setWindowTitle('Feedbooks')
d = d.exec_()
def search(self, query, max_results=10, timeout=60):
url = 'http://m.feedbooks.com/search?query=' + urllib2.quote(query)
br = browser()
counter = max_results
with closing(br.open(url, timeout=timeout)) as f:
doc = html.fromstring(f.read())
for data in doc.xpath('//ul[@class="m-list"]//li'):
if counter <= 0:
break
data = html.fromstring(html.tostring(data))
id = ''
id_a = data.xpath('//a[@class="buy"]')
if id_a:
id = id_a[0].get('href', None)
id = id.split('/')[-2]
id = '/item/' + id
else:
id_a = data.xpath('//a[@class="download"]')
if id_a:
id = id_a[0].get('href', None)
id = id.split('/')[-1]
id = id.split('.')[0]
id = '/book/' + id
if not id:
continue
title = ''.join(data.xpath('//h5/a/text()'))
author = ''.join(data.xpath('//h6/a/text()'))
price = ''.join(data.xpath('//a[@class="buy"]/text()'))
if not price:
price = '$0.00'
counter -= 1
yield ('', title.strip(), author.strip(), price.replace(' ', '').strip(), id.strip())

View File

@ -21,7 +21,7 @@ class GutenbergStore(StorePlugin):
def open(self, gui, parent=None, start_item=None):
from calibre.gui2.store.web_store_dialog import WebStoreDialog
d = WebStoreDialog(gui, 'http://m.gutenberg.org/', parent, start_item)
d.setWindowTitle('Free eBooks by Project Gutenberg')
d.setWindowTitle('Project Gutenberg')
d = d.exec_()
def search(self, query, max_results=10, timeout=60):

View File

@ -21,7 +21,7 @@ class ManyBooksStore(StorePlugin):
def open(self, gui, parent=None, start_item=None):
from calibre.gui2.store.web_store_dialog import WebStoreDialog
d = WebStoreDialog(gui, 'http://manybooks.net/', parent, start_item)
d.setWindowTitle('Ad-free eBooks for your eBook reader')
d.setWindowTitle('ManyBooks')
d = d.exec_()
def search(self, query, max_results=10, timeout=60):

View File

@ -4,6 +4,7 @@ __license__ = 'GPL 3'
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
import re
import urllib
from PyQt4.Qt import QDialog, QUrl
@ -37,11 +38,13 @@ class WebStoreDialog(QDialog, Ui_Dialog):
def load_finished(self, ok=True):
self.progress.setValue(100)
#if not ok:
# print 'Error'
def go_home(self, checked=False, detail_item=None):
url = self.base_url
if detail_item:
url += '/' + urllib.quote(detail_item)
# Reduce redundant /'s because some stores
# (Feedbooks) and server frameworks (cherrypy)
# choke on them.
url = re.sub(r'(?<!http:)/{2,}', '/', url)
self.view.load(QUrl(url))