From bae22ca387b58a2fd5e603f01ffb1da430acc7f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Tue, 20 Nov 2012 22:46:14 +0100 Subject: [PATCH] publio store plugin --- src/calibre/customize/builtins.py | 10 +++ .../gui2/store/stores/publio_plugin.py | 80 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/calibre/gui2/store/stores/publio_plugin.py diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 693a9c4a6a..4aa24524a0 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1566,6 +1566,15 @@ class StorePragmaticBookshelfStore(StoreBase): headquarters = 'US' formats = ['EPUB', 'MOBI', 'PDF'] +class StorePublioStore(StoreBase): + name = 'Publio' + description = u'Publio.pl to księgarnia internetowa, w której mogą Państwo nabyć e-booki i audiobooki.' + actual_plugin = 'calibre.gui2.store.stores.publio_plugin:PublioStore' + author = u'Tomasz Długosz' + + headquarters = 'PL' + formats = ['EPUB', 'MOBI', 'PDF'] + class StoreRW2010Store(StoreBase): name = 'RW2010' description = u'Polski serwis self-publishingowy. Pliki PDF, EPUB i MOBI. Maksymalna cena utworu nie przekracza u nas 10 złotych!' @@ -1689,6 +1698,7 @@ plugins += [ StoreOpenBooksStore, StoreOzonRUStore, StorePragmaticBookshelfStore, + StorePublioStore, StoreRW2010Store, StoreSmashwordsStore, StoreVirtualoStore, diff --git a/src/calibre/gui2/store/stores/publio_plugin.py b/src/calibre/gui2/store/stores/publio_plugin.py new file mode 100644 index 0000000000..be714300a9 --- /dev/null +++ b/src/calibre/gui2/store/stores/publio_plugin.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- + +from __future__ import (unicode_literals, division, absolute_import, print_function) + +__license__ = 'GPL 3' +__copyright__ = '2012, Tomasz Długosz ' +__docformat__ = 'restructuredtext en' + +import re +import urllib +from contextlib import closing + +from lxml import html + +from PyQt4.Qt import QUrl + +from calibre import browser, url_slash_cleaner +from calibre.gui2 import open_url +from calibre.gui2.store import StorePlugin +from calibre.gui2.store.basic_config import BasicStoreConfig +from calibre.gui2.store.search_result import SearchResult +from calibre.gui2.store.web_store_dialog import WebStoreDialog + +class PublioStore(BasicStoreConfig, StorePlugin): + + def open(self, parent=None, detail_item=None, external=False): + google_analytics = '?utm_source=tdcalibre' + url = 'http://www.publio.pl/e-booki.html' + google_analytics + + if external or self.config.get('open_external', False): + open_url(QUrl(url_slash_cleaner((detail_item + google_analytics) if detail_item else url))) + else: + d = WebStoreDialog(self.gui, url, parent, detail_item) + d.setWindowTitle(self.name) + d.set_tags(self.config.get('tags', '')) + d.exec_() + + def search(self, query, max_results=20, timeout=60): + + br = browser() + + counter = max_results + page = 1 + while counter: + with closing(br.open('http://www.publio.pl/e-booki,strona' + str(page) + '.html?q=' + urllib.quote(query), timeout=timeout)) as f: + doc = html.fromstring(f.read()) + for data in doc.xpath('//div[@class="item"]'): + if counter <= 0: + break + + id = ''.join(data.xpath('.//div[@class="img"]/a/@href')) + if not id: + continue + + cover_url = ''.join(data.xpath('.//div[@class="img"]/a/img/@data-original')) + title = ''.join(data.xpath('.//div[@class="desc"]/h4/a/text()')) + title2 = ''.join(data.xpath('.//div[@class="desc"]/h5/a/text()')) + if title2: + title = title + '. ' + title2 + author = ', '.join(data.xpath('./div[@class="desc"]/div[@class="detailShortList"]/div[@class="row"]/a/text()')) + price = ''.join(data.xpath('.//div[@class="priceBoxContener "]/div/ins/text()')) + if not price: + price = ''.join(data.xpath('.//div[@class="priceBoxContener "]/div/text()')) + formats = ', '.join(data.xpath('.//div[@class="formats"]/a/img/@alt')) + + counter -= 1 + + s = SearchResult() + s.cover_url = 'http://www.publio.pl' + cover_url + s.title = title.strip() + s.author = author.strip() + s.price = price.strip() + s.detail_item = 'http://www.publio.pl' + id.strip() + s.drm = SearchResult.DRM_LOCKED if 'DRM' in formats else SearchResult.DRM_UNLOCKED + s.formats = formats.replace(' DRM','').strip() + + yield s + if not doc.xpath('boolean(//a[@class="next"])'): + break + page+=1