{
  "amazon_mx": "#!/usr/bin/env python\n#\n# License: GPLv3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>\n\nstore_version = 1  # Needed for dynamic plugin loading\n\nfrom calibre.gui2.store import StorePlugin\n\ntry:\n    from calibre.gui2.store.amazon_base import AmazonStore\nexcept ImportError:\n    class AmazonStore:\n        minimum_calibre_version = 9999, 0, 0\n\n\nclass Base(AmazonStore):\n    scraper_storage = []\n    SEARCH_BASE_URL = 'https://www.amazon.com.mx/s/'\n    SEARCH_BASE_QUERY = {'url': 'search-alias=digital-text'}\n    DETAILS_URL = 'https://amazon.com.mx/dp/'\n    STORE_LINK =  'https://www.amazon.com.mx'\n\n\nclass AmazonKindleStore(Base, StorePlugin):\n    pass\n\n\nif __name__ == '__main__':\n    Base().develop_plugin()\n",
  "ebookshoppe_uk": "# -*-\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nstore_version = 1  # Needed for dynamic plugin loading\n\n__license__ = 'GPL 3'\n__copyright__ = '2011, John Schember <john@nachtimwald.com>'\n__docformat__ = 'restructuredtext en'\n\ntry:\n    from urllib.parse import quote\nexcept ImportError:\n    from urllib2 import quote\nfrom contextlib import closing\n\nfrom lxml import html\nfrom qt.core import QUrl\n\nfrom calibre import browser\nfrom calibre.gui2 import open_url\nfrom calibre.gui2.store import StorePlugin\nfrom calibre.gui2.store.basic_config import BasicStoreConfig\nfrom calibre.gui2.store.search_result import SearchResult\nfrom calibre.gui2.store.web_store_dialog import WebStoreDialog\n\n\nclass EBookShoppeUKStore(BasicStoreConfig, StorePlugin):\n\n    def open(self, parent=None, detail_item=None, external=False):\n        url_details = 'http://www.awin1.com/cread.php?awinmid=1414&awinaffid=120917&clickref=&p={0}'\n        url = 'http://www.awin1.com/awclick.php?mid=2666&id=120917'\n\n        if external or self.config.get('open_external', False):\n            if detail_item:\n                url = url_details.format(detail_item)\n            open_url(QUrl(url))\n        else:\n            detail_url = None\n            if detail_item:\n                detail_url = url_details.format(detail_item)\n            d = WebStoreDialog(self.gui, url, parent, detail_url)\n            d.setWindowTitle(self.name)\n            d.set_tags(self.config.get('tags', ''))\n            d.exec()\n\n    def search(self, query, max_results=10, timeout=60):\n        url = 'http://www.ebookshoppe.com/search.php?search_query=' + quote(query)\n        br = browser()\n        br.addheaders = [(\"Referer\", \"http://www.ebookshoppe.com/\")]\n\n        counter = max_results\n        with closing(br.open(url, timeout=timeout)) as f:\n            doc = html.fromstring(f.read())\n            for data in doc.xpath('//ul[@class=\"ProductList\"]/li'):\n                if counter <= 0:\n                    break\n\n                id = ''.join(data.xpath('./div[@class=\"ProductDetails\"]/'\n                                        'strong/a/@href')).strip()\n                if not id:\n                    continue\n                cover_url = ''.join(data.xpath('./div[@class=\"ProductImage\"]/a/img/@src'))\n                title = ''.join(data.xpath('./div[@class=\"ProductDetails\"]/strong/a/text()'))\n                price = ''.join(data.xpath('./div[@class=\"ProductPriceRating\"]/em/text()'))\n                counter -= 1\n\n                s = SearchResult()\n                s.cover_url = cover_url\n                s.title = title.strip()\n                s.price = price\n                s.drm = SearchResult.DRM_UNLOCKED\n                s.detail_item = id\n\n                self.get_author_and_formats(s, timeout)\n                if not s.author:\n                    continue\n\n                yield s\n\n    def get_author_and_formats(self, search_result, timeout):\n        br = browser()\n        with closing(br.open(search_result.detail_item, timeout=timeout)) as nf:\n            idata = html.fromstring(nf.read())\n            author = ''.join(idata.xpath('//div[@id=\"ProductOtherDetails\"]/dl/dd[1]/text()'))\n            if author:\n                search_result.author = author\n            formats = idata.xpath('//dl[@class=\"ProductAddToCart\"]/dd/'\n                                  'ul[@class=\"ProductOptionList\"]/li/label/text()')\n            if formats:\n                search_result.formats = ', '.join(formats)\n            search_result.drm = SearchResult.DRM_UNKNOWN\n        return True\n",
  "ozon_ru": "# -*-\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nstore_version = 3  # Needed for dynamic plugin loading\n\n__license__ = 'GPL 3'\n__copyright__ = '2011-2013, Roman Mukhin <ramses_ru at hotmail.com>'\n__docformat__ = 'restructuredtext en'\n\nfrom contextlib import closing\n\ntry:\n    from urllib.parse import quote_plus\nexcept ImportError:\n    from urllib import quote_plus\n\nfrom qt.core import QUrl\n\nfrom calibre import browser, url_slash_cleaner\nfrom calibre.ebooks.chardet import xml_to_unicode\nfrom calibre.gui2 import open_url\nfrom calibre.gui2.store import StorePlugin\nfrom calibre.gui2.store.search_result import SearchResult\nfrom calibre.gui2.store.web_store_dialog import WebStoreDialog\n\nshop_url = 'http://www.ozon.ru'\n\n\ndef parse_html(raw):\n    try:\n        from html5_parser import parse\n    except ImportError:\n        # Old versions of calibre\n        import html5lib\n        return html5lib.parse(raw, treebuilder='lxml', namespaceHTMLElements=False)\n    else:\n        return parse(raw)\n\n\ndef search(query, max_results=15, timeout=60):\n    url = 'http://www.ozon.ru/?context=search&text=%s&store=1,0&group=div_book' % quote_plus(query)\n\n    counter = max_results\n    br = browser()\n\n    with closing(br.open(url, timeout=timeout)) as f:\n        raw = xml_to_unicode(f.read(), strip_encoding_pats=True, assume_utf8=True)[0]\n        root = parse_html(raw)\n        for tile in root.xpath('//*[@class=\"bShelfTile inline\"]'):\n            if counter <= 0:\n                break\n            counter -= 1\n\n            s = SearchResult(store_name='OZON.ru')\n            s.detail_item = shop_url + tile.xpath('descendant::a[@class=\"eShelfTile_Link\"]/@href')[0]\n            s.title = tile.xpath('descendant::span[@class=\"eShelfTile_ItemNameText\"]/@title')[0]\n            s.author = tile.xpath('descendant::span[@class=\"eShelfTile_ItemPerson\"]/@title')[0]\n            s.price = ''.join(tile.xpath('descendant::div[contains(@class, \"eShelfTile_Price\")]/text()'))\n            s.cover_url = 'http:' + tile.xpath('descendant::img/@data-original')[0]\n            s.price = format_price_in_RUR(s.price)\n            yield s\n\n\nclass OzonRUStore(StorePlugin):\n\n    def open(self, parent=None, detail_item=None, external=False):\n        url = detail_item or shop_url\n        if external or self.config.get('open_external', False):\n            open_url(QUrl(url_slash_cleaner(url)))\n        else:\n            d = WebStoreDialog(self.gui, shop_url, parent, url)\n            d.setWindowTitle(self.name)\n            d.set_tags(self.config.get('tags', ''))\n            d.exec()\n\n    def search(self, query, max_results=15, timeout=60):\n        for s in search(query, max_results=max_results, timeout=timeout):\n            yield s\n\n\ndef format_price_in_RUR(price):\n    '''\n    Try to format price according ru locale: '12 212,34 руб.'\n    @param price: price in format like 25.99\n    @return: formatted price if possible otherwise original value\n    @rtype: unicode\n    '''\n    price = price.replace('\\xa0', '').replace(',', '.').strip() + ' py6'\n    return price\n\n\nif __name__ == '__main__':\n    import sys\n    for r in search(sys.argv[-1]):\n        print(r)\n"
}