From 381cd47f71408ab09e93322e5042fb03c4fd7b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Sun, 7 Apr 2013 15:55:10 +0200 Subject: [PATCH] koobe draft --- src/calibre/customize/builtins.py | 9 +++ src/calibre/gui2/store/stores/koobe_plugin.py | 71 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/calibre/gui2/store/stores/koobe_plugin.py diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 474617c911..c14cd26c6e 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1467,6 +1467,15 @@ class StoreKoboStore(StoreBase): formats = ['EPUB'] affiliate = True +class StoreBookotekaStore(StoreBase): + name = 'Koobe' + author = u'Tomasz Długosz' + description = u'Księgarnia internetowa oferuje ebooki (książki elektroniczne) w postaci plików epub, mobi i pdf.' + actual_plugin = 'calibre.gui2.store.stores.koobe_plugin:KoobeStore' + + headquarters = 'PL' + formats = ['EPUB', 'MOBI', 'PDF'] + class StoreLegimiStore(StoreBase): name = 'Legimi' author = u'Tomasz Długosz' diff --git a/src/calibre/gui2/store/stores/koobe_plugin.py b/src/calibre/gui2/store/stores/koobe_plugin.py new file mode 100644 index 0000000000..ffb9a26a7f --- /dev/null +++ b/src/calibre/gui2/store/stores/koobe_plugin.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- + +from __future__ import (unicode_literals, division, absolute_import, print_function) +store_version = 1 # Needed for dynamic plugin loading + +__license__ = 'GPL 3' +__copyright__ = '2013, 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 KoobeStore(BasicStoreConfig, StorePlugin): + + def open(self, parent=None, detail_item=None, external=False): + url = 'http://www.koobe.pl/' + + if external or self.config.get('open_external', False): + open_url(QUrl(url_slash_cleaner(detail_item))) + 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=12, timeout=60): + url = 'http://www.koobe.pl/szukaj/fraza:' + urllib.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('//div[@class="seach_result"]/div[@class="result"]'): + if counter <= 0: + break + + id = ''.join(data.xpath('.//div[@class="cover"]/a/@href')) + if not id: + continue + + cover_url = ''.join(data.xpath('.//div[@class="cover"]/a/img/@src')) + price = ''.join(data.xpath('.//span[@class="current_price"]/text()')) + title = ''.join(data.xpath('.//h2[@class="title"]/a/text()')) + author = ''.join(data.xpath('.//h3[@class="book_author"]/a/text()')) + formats = ''.join(data.xpath('.//div[@class="formats"]/div/div/@title')) + + counter -= 1 + + s = SearchResult() + s.cover_url = 'http://koobe.pl/' + cover_url + s.title = title.strip() + s.author = author.strip() + s.price = price + ' zł' + s.detail_item = 'http://koobe.pl' + id[1:] + s.formats = ', '.join(formats).upper() + s.drm = SearchResult.DRM_UNKNOWN + + yield s