Compare commits
3 Commits
fc96806830
...
da7a7658e6
Author | SHA1 | Date |
---|---|---|
ibu ☉ radempa | da7a7658e6 | |
ibu ☉ radempa | ec1725c507 | |
ibu ☉ radempa | e4daeb15d2 |
7
DEVEL.md
7
DEVEL.md
|
@ -13,7 +13,6 @@ Environment:
|
||||||
|
|
||||||
## Release process
|
## Release process
|
||||||
|
|
||||||
cd REPO_ROOT
|
Edit the version in theanarchistlibrary_store/__init__.py and
|
||||||
VERSION="1.1.0"
|
in the repo root call
|
||||||
cd theanarchistlibrary_store
|
./release.py
|
||||||
zip ../releases/theanarchistlibrary_store_v${VERSION}.zip *
|
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import glob
|
||||||
|
import os
|
||||||
|
from zipfile import ZipFile
|
||||||
|
|
||||||
|
|
||||||
|
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
|
|
||||||
|
def get_version():
|
||||||
|
path = os.path.join(
|
||||||
|
dir_path,
|
||||||
|
'theanarchistlibrary_store',
|
||||||
|
'__init__.py',
|
||||||
|
)
|
||||||
|
with open(path, 'r') as file:
|
||||||
|
lines = file.read().split('\n')
|
||||||
|
for line in lines:
|
||||||
|
line_ = line.lower().strip()
|
||||||
|
if line_.startswith('version = '):
|
||||||
|
parts = line_[10:].lstrip('(').rstrip(')').split(',')
|
||||||
|
numbers = [int(part) for part in parts]
|
||||||
|
return '{}.{}.{}'.format(*numbers)
|
||||||
|
|
||||||
|
|
||||||
|
def release():
|
||||||
|
version = get_version()
|
||||||
|
tgt_fn = f'theanarchistlibrary_store_v{version}.zip'
|
||||||
|
tgt_path = os.path.join(dir_path, 'releases', tgt_fn)
|
||||||
|
src_glob = os.path.join(
|
||||||
|
dir_path,
|
||||||
|
'theanarchistlibrary_store',
|
||||||
|
'**',
|
||||||
|
)
|
||||||
|
with ZipFile(tgt_path, 'w') as zip:
|
||||||
|
for path in glob.glob(src_glob, recursive=True):
|
||||||
|
arcname = path[(len(src_glob) - 2):]
|
||||||
|
if arcname:
|
||||||
|
zip.write(path, arcname=arcname)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
release()
|
Binary file not shown.
|
@ -1,14 +1,15 @@
|
||||||
__license__ = 'GPL 3'
|
__license__ = 'GPL 3'
|
||||||
__copyright__ = '2012, Ruben Pollan <meskio@sindominio.net>'
|
__copyright__ = '2012, Ruben Pollan <meskio@sindominio.net>; 2020, ibu radempa <ibu@radempa.de>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
from calibre.customize import StoreBase
|
from calibre.customize import StoreBase
|
||||||
|
|
||||||
|
|
||||||
class TheAnarchistLibraryStore(StoreBase):
|
class TheAnarchistLibraryStore(StoreBase):
|
||||||
name = 'The Anarchist Library'
|
name = 'The Anarchist Library'
|
||||||
description = 'theanarchistlibrary.org is (despite its name) an archive focusing on anarchism, anarchist texts, and texts of interest for anarchists.'
|
description = 'theanarchistlibrary.org is an archive focusing on anarchism, anarchist texts, and texts of interest to anarchists.'
|
||||||
author = 'Ruben Pollan'
|
author = 'Ruben Pollan; ibu radempa'
|
||||||
version = (1, 0, 0)
|
version = (1, 2, 0)
|
||||||
drm_free_only = True
|
drm_free_only = True
|
||||||
formats = ['EPUB', 'PDF', 'TXT', 'TEX', 'MUSE']
|
formats = ['EPUB', 'PDF', 'TXT', 'TEX', 'MUSE']
|
||||||
actual_plugin = 'calibre_plugins.store_theanarchistlibrary.theanarchistlibrary_plugin:TheAnarchistLibraryStore'
|
actual_plugin = 'calibre_plugins.store_theanarchistlibrary.theanarchistlibrary_plugin:TheAnarchistLibraryStore'
|
||||||
|
|
|
@ -1,24 +1,37 @@
|
||||||
__license__ = 'GPL 3'
|
__license__ = 'GPL 3'
|
||||||
__copyright__ = '2012, Ruben Pollan <meskio@sindominio.net>'
|
__copyright__ = '2012, Ruben Pollan <meskio@sindominio.net>; 2020, ibu radempa <ibu@radempa.de>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
import json
|
||||||
try:
|
try:
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote_plus as quote
|
||||||
except:
|
except:
|
||||||
from urllib2 import quote
|
from urllib2 import quote
|
||||||
try:
|
try:
|
||||||
from PyQt5.Qt import QUrl
|
from PyQt5.Qt import QUrl
|
||||||
except:
|
except:
|
||||||
from PyQt4.Qt import QUrl
|
from PyQt4.Qt import QUrl
|
||||||
|
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
import json
|
|
||||||
from calibre import browser
|
from calibre import browser
|
||||||
from calibre.gui2 import open_url
|
from calibre.gui2 import open_url
|
||||||
from calibre.gui2.store import StorePlugin
|
from calibre.gui2.store import StorePlugin
|
||||||
from calibre.gui2.store.basic_config import BasicStoreConfig
|
from calibre.gui2.store.basic_config import BasicStoreConfig
|
||||||
from calibre.gui2.store.search_result import SearchResult
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
||||||
|
from . import TheAnarchistLibraryStore
|
||||||
|
|
||||||
|
|
||||||
|
url1 = 'https://theanarchistlibrary.org/search?fmt=json&page=%s&query=%s'
|
||||||
|
url2 = 'https://usa.anarchistlibraries.net/search?fmt=json&page=%s&query=%s'
|
||||||
|
"""Search URLs. If the library has no fallback url, set url2 = None."""
|
||||||
|
|
||||||
|
|
||||||
|
max_pages = 10
|
||||||
|
"""Page limit. (amusewiki gives us 10 results per page.)"""
|
||||||
|
|
||||||
|
|
||||||
|
user_agent = 'Calibre plugin calibre-tal v' + '{}.{}.{}'.format(*TheAnarchistLibraryStore.version)
|
||||||
|
|
||||||
|
|
||||||
class TheAnarchistLibraryStore(BasicStoreConfig, StorePlugin):
|
class TheAnarchistLibraryStore(BasicStoreConfig, StorePlugin):
|
||||||
|
|
||||||
|
@ -33,14 +46,28 @@ class TheAnarchistLibraryStore(BasicStoreConfig, StorePlugin):
|
||||||
d.set_tags(self.config.get('tags', ''))
|
d.set_tags(self.config.get('tags', ''))
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
|
||||||
def search(self, query, max_results=10, timeout=60):
|
def search(self, query, max_results=10, timeout=10):
|
||||||
url = 'http://theanarchistlibrary.org/search?fmt=json&query=' + quote(query)
|
br = browser(user_agent=user_agent)
|
||||||
|
page = 0
|
||||||
|
while page < max_pages:
|
||||||
|
page += 1
|
||||||
|
try:
|
||||||
|
for result in self._iter_search_results(br, url1, page, query, timeout):
|
||||||
|
if result is False:
|
||||||
|
return
|
||||||
|
yield result
|
||||||
|
except:
|
||||||
|
if url2:
|
||||||
|
for result in self._iter_search_results(br, url2, page, query, timeout):
|
||||||
|
if result is False:
|
||||||
|
return
|
||||||
|
yield result
|
||||||
|
|
||||||
br = browser()
|
def _iter_search_results(self, br, url, page, query, timeout):
|
||||||
|
with closing(br.open(url % (page, quote(query)), timeout=timeout)) as f:
|
||||||
counter = max_results
|
|
||||||
with closing(br.open(url, timeout=timeout)) as f:
|
|
||||||
doc = json.load(f)
|
doc = json.load(f)
|
||||||
|
if not doc:
|
||||||
|
yield False
|
||||||
for data in doc:
|
for data in doc:
|
||||||
s = SearchResult()
|
s = SearchResult()
|
||||||
s.title = data['title'].strip()
|
s.title = data['title'].strip()
|
||||||
|
@ -52,9 +79,5 @@ class TheAnarchistLibraryStore(BasicStoreConfig, StorePlugin):
|
||||||
s.downloads['PDF'] = data['url'].strip() + '.pdf'
|
s.downloads['PDF'] = data['url'].strip() + '.pdf'
|
||||||
s.downloads['A4.PDF'] = data['url'].strip() + '.a4.pdf'
|
s.downloads['A4.PDF'] = data['url'].strip() + '.a4.pdf'
|
||||||
s.downloads['LT.PDF'] = data['url'].strip() + '.lt.pdf'
|
s.downloads['LT.PDF'] = data['url'].strip() + '.lt.pdf'
|
||||||
s.downloads['TXT'] = data['url'].strip() + '.txt'
|
s.formats = 'EPUB, PDF, A4.PDF, LT.PDF'
|
||||||
s.downloads['TEX'] = data['url'].strip() + '.tex'
|
|
||||||
s.downloads['MUSE'] = data['url'].strip() + '.muse'
|
|
||||||
s.formats = 'EPUB, PDF, A4.PDF, LT.PDF, TXT, TEX, MUSE'
|
|
||||||
|
|
||||||
yield s
|
yield s
|
||||||
|
|
Loading…
Reference in New Issue