mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
automated fixes by pyupgrade to py 3.8
This commit is contained in:
parent
c08be4e428
commit
85a0056e6d
@ -13,7 +13,7 @@ CSIDL_PROGRAM_FILES = 38
|
|||||||
CSIDL_PROGRAM_FILESX86 = 42
|
CSIDL_PROGRAM_FILESX86 = 42
|
||||||
|
|
||||||
|
|
||||||
@lru_cache()
|
@lru_cache
|
||||||
def get_program_files_location(which=CSIDL_PROGRAM_FILESX86):
|
def get_program_files_location(which=CSIDL_PROGRAM_FILESX86):
|
||||||
SHGFP_TYPE_CURRENT = 0
|
SHGFP_TYPE_CURRENT = 0
|
||||||
buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
|
buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
|
||||||
@ -22,7 +22,7 @@ def get_program_files_location(which=CSIDL_PROGRAM_FILESX86):
|
|||||||
return buf.value
|
return buf.value
|
||||||
|
|
||||||
|
|
||||||
@lru_cache()
|
@lru_cache
|
||||||
def find_vswhere():
|
def find_vswhere():
|
||||||
for which in (CSIDL_PROGRAM_FILESX86, CSIDL_PROGRAM_FILES):
|
for which in (CSIDL_PROGRAM_FILESX86, CSIDL_PROGRAM_FILES):
|
||||||
root = get_program_files_location(which)
|
root = get_program_files_location(which)
|
||||||
@ -37,7 +37,7 @@ def get_output(*cmd):
|
|||||||
return subprocess.check_output(cmd, encoding='mbcs', errors='strict')
|
return subprocess.check_output(cmd, encoding='mbcs', errors='strict')
|
||||||
|
|
||||||
|
|
||||||
@lru_cache()
|
@lru_cache
|
||||||
def find_visual_studio():
|
def find_visual_studio():
|
||||||
path = get_output(
|
path = get_output(
|
||||||
find_vswhere(),
|
find_vswhere(),
|
||||||
@ -52,7 +52,7 @@ def find_visual_studio():
|
|||||||
return os.path.join(path, "VC", "Auxiliary", "Build")
|
return os.path.join(path, "VC", "Auxiliary", "Build")
|
||||||
|
|
||||||
|
|
||||||
@lru_cache()
|
@lru_cache
|
||||||
def find_msbuild():
|
def find_msbuild():
|
||||||
base_path = get_output(
|
base_path = get_output(
|
||||||
find_vswhere(),
|
find_vswhere(),
|
||||||
@ -113,12 +113,12 @@ def query_process(cmd, is64bit):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@lru_cache()
|
@lru_cache
|
||||||
def query_vcvarsall(is64bit=True):
|
def query_vcvarsall(is64bit=True):
|
||||||
plat = 'amd64' if is64bit else 'amd64_x86'
|
plat = 'amd64' if is64bit else 'amd64_x86'
|
||||||
vcvarsall = find_vcvarsall()
|
vcvarsall = find_vcvarsall()
|
||||||
env = query_process(f'"{vcvarsall}" {plat} & set', is64bit)
|
env = query_process(f'"{vcvarsall}" {plat} & set', is64bit)
|
||||||
pat = re.compile('vs(\d+)comntools', re.I)
|
pat = re.compile(r'vs(\d+)comntools', re.I)
|
||||||
|
|
||||||
comn_tools = {}
|
comn_tools = {}
|
||||||
|
|
||||||
|
@ -759,7 +759,7 @@ def initialize_plugins(perf=False):
|
|||||||
if perf:
|
if perf:
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import time
|
import time
|
||||||
times = defaultdict(lambda:0)
|
times = defaultdict(int)
|
||||||
|
|
||||||
for zfp, installation_type in chain(
|
for zfp, installation_type in chain(
|
||||||
zip_value(external_plugins.items(), PluginInstallationType.EXTERNAL),
|
zip_value(external_plugins.items(), PluginInstallationType.EXTERNAL),
|
||||||
|
@ -59,7 +59,7 @@ class BackupProgress:
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
prints(
|
prints(
|
||||||
'{:.1f}% {} failed'.format((self.count * 100) / float(self.total), book_id))
|
f'{(self.count * 100) / float(self.total):.1f}% {book_id} failed')
|
||||||
|
|
||||||
|
|
||||||
def main(opts, args, dbctx):
|
def main(opts, args, dbctx):
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
from calibre.utils.resources import get_path as P
|
from calibre.utils.resources import get_path as P
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ class FTSAPITest(BaseTest):
|
|||||||
|
|
||||||
# check enabling scans pre-exisintg
|
# check enabling scans pre-exisintg
|
||||||
cache = self.new_library()
|
cache = self.new_library()
|
||||||
cache.add_format(1, 'TXTZ', self.make_txtz('a test te\u00adxt'.encode('utf-8')))
|
cache.add_format(1, 'TXTZ', self.make_txtz('a test te\u00adxt'.encode()))
|
||||||
fts = cache.enable_fts()
|
fts = cache.enable_fts()
|
||||||
self.wait_for_fts_to_finish(fts)
|
self.wait_for_fts_to_finish(fts)
|
||||||
check(id=1, book=1, format='TXTZ', searchable_text='a test text')
|
check(id=1, book=1, format='TXTZ', searchable_text='a test text')
|
||||||
|
@ -54,4 +54,4 @@ class PageGroup:
|
|||||||
values = str(self.__first_value)
|
values = str(self.__first_value)
|
||||||
else:
|
else:
|
||||||
values = "|".join(self.__page_number_labels)
|
values = "|".join(self.__page_number_labels)
|
||||||
return "(%s,%s,%s)" % (starting_location, self.__page_number_type.value, values)
|
return "({},{},{})".format(starting_location, self.__page_number_type.value, values)
|
||||||
|
@ -212,7 +212,7 @@ class KOBO(USBMS):
|
|||||||
debug_print(f"device_version_info - version_file={version_file}")
|
debug_print(f"device_version_info - version_file={version_file}")
|
||||||
if os.path.isfile(version_file):
|
if os.path.isfile(version_file):
|
||||||
debug_print("device_version_info - have opened version_file")
|
debug_print("device_version_info - have opened version_file")
|
||||||
vf = open(version_file, "r")
|
vf = open(version_file)
|
||||||
self._device_version_info = vf.read().strip().split(",")
|
self._device_version_info = vf.read().strip().split(",")
|
||||||
vf.close()
|
vf.close()
|
||||||
debug_print("device_version_info - self._device_version_info=", self._device_version_info)
|
debug_print("device_version_info - self._device_version_info=", self._device_version_info)
|
||||||
|
@ -87,7 +87,7 @@ def option_recommendation_to_cli_option(add_option, rec):
|
|||||||
switches.append('--'+opt.long_switch)
|
switches.append('--'+opt.long_switch)
|
||||||
attrs = dict(dest=opt.name, help=opt.help,
|
attrs = dict(dest=opt.name, help=opt.help,
|
||||||
choices=opt.choices, default=rec.recommended_value)
|
choices=opt.choices, default=rec.recommended_value)
|
||||||
if isinstance(rec.recommended_value, type(True)):
|
if isinstance(rec.recommended_value, bool):
|
||||||
attrs['action'] = 'store_false' if rec.recommended_value else \
|
attrs['action'] = 'store_false' if rec.recommended_value else \
|
||||||
'store_true'
|
'store_true'
|
||||||
else:
|
else:
|
||||||
|
@ -277,7 +277,7 @@ class HTMLInput(InputFormatPlugin):
|
|||||||
if not q.startswith(self.root_dir_of_input):
|
if not q.startswith(self.root_dir_of_input):
|
||||||
if not self.opts.allow_local_files_outside_root:
|
if not self.opts.allow_local_files_outside_root:
|
||||||
if os.path.exists(q):
|
if os.path.exists(q):
|
||||||
self.log.warn('Not adding {} as it is outside the document root: {}'.format(q, self.root_dir_of_input))
|
self.log.warn(f'Not adding {q} as it is outside the document root: {self.root_dir_of_input}')
|
||||||
return None, None
|
return None, None
|
||||||
return link, frag
|
return link, frag
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ def mi_to_html(
|
|||||||
note = ''
|
note = ''
|
||||||
item_id = None if item_id_if_has_note is None else item_id_if_has_note(field, field_value)
|
item_id = None if item_id_if_has_note is None else item_id_if_has_note(field, field_value)
|
||||||
if item_id is not None:
|
if item_id is not None:
|
||||||
note = ' <a title="{0}" href="{1}">{2}</a>'.format(
|
note = ' <a title="{}" href="{}">{}</a>'.format(
|
||||||
_('Show notes for: {}').format(field_value), notes_action(field=field, value=field_value, item_id=item_id), note_markup)
|
_('Show notes for: {}').format(field_value), notes_action(field=field, value=field_value, item_id=item_id), note_markup)
|
||||||
return link + note
|
return link + note
|
||||||
return ''
|
return ''
|
||||||
|
@ -12,7 +12,7 @@ from calibre.ebooks.metadata import MetaInformation, string_to_authors
|
|||||||
|
|
||||||
# The priorities for loading metadata from different file types
|
# The priorities for loading metadata from different file types
|
||||||
# Higher values should be used to update metadata from lower values
|
# Higher values should be used to update metadata from lower values
|
||||||
METADATA_PRIORITIES = collections.defaultdict(lambda:0)
|
METADATA_PRIORITIES = collections.defaultdict(int)
|
||||||
for i, ext in enumerate((
|
for i, ext in enumerate((
|
||||||
'html', 'htm', 'xhtml', 'xhtm',
|
'html', 'htm', 'xhtml', 'xhtm',
|
||||||
'rtf', 'fb2', 'pdf', 'prc', 'odt',
|
'rtf', 'fb2', 'pdf', 'prc', 'odt',
|
||||||
|
@ -38,7 +38,7 @@ class FDST:
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
ans = ['FDST record']
|
ans = ['FDST record']
|
||||||
def a(k, v):
|
def a(k, v):
|
||||||
return ans.append('%s: %s' % (k, v))
|
return ans.append('{}: {}'.format(k, v))
|
||||||
a('Offset to sections', self.sec_off)
|
a('Offset to sections', self.sec_off)
|
||||||
a('Number of section records', self.num_sections)
|
a('Number of section records', self.num_sections)
|
||||||
ans.append('**** %d Sections ****'% len(self.sections))
|
ans.append('**** %d Sections ****'% len(self.sections))
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
# Workaround a bunch of brain dead changes in PyQt6 that break backwards compat
|
# Workaround a bunch of brain dead changes in PyQt6 that break backwards compat
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
from qt.core import QUrl
|
from qt.core import QUrl
|
||||||
@ -48,8 +47,7 @@ class AmazonStore:
|
|||||||
open_url(QUrl(store_link))
|
open_url(QUrl(store_link))
|
||||||
|
|
||||||
def search(self, query, max_results=10, timeout=60):
|
def search(self, query, max_results=10, timeout=60):
|
||||||
for result in get_method('search_amazon')(self, query, max_results=max_results, timeout=timeout):
|
yield from get_method('search_amazon')(self, query, max_results=max_results, timeout=timeout)
|
||||||
yield result
|
|
||||||
|
|
||||||
def get_details(self, search_result, timeout):
|
def get_details(self, search_result, timeout):
|
||||||
return get_method('get_details_amazon')(self, search_result, timeout)
|
return get_method('get_details_amazon')(self, search_result, timeout)
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
@ -19,7 +18,7 @@ def search_amazon(self, query, max_results=10, timeout=60, write_html_to=None):
|
|||||||
uquery[field_keywords] = query
|
uquery[field_keywords] = query
|
||||||
|
|
||||||
def asbytes(x):
|
def asbytes(x):
|
||||||
if isinstance(x, type('')):
|
if isinstance(x, str):
|
||||||
x = x.encode('utf-8')
|
x = x.encode('utf-8')
|
||||||
return x
|
return x
|
||||||
uquery = {asbytes(k):asbytes(v) for k, v in uquery.items()}
|
uquery = {asbytes(k):asbytes(v) for k, v in uquery.items()}
|
||||||
@ -32,7 +31,7 @@ def search_amazon(self, query, max_results=10, timeout=60, write_html_to=None):
|
|||||||
f.write(raw)
|
f.write(raw)
|
||||||
doc = html.fromstring(raw)
|
doc = html.fromstring(raw)
|
||||||
for result in doc.xpath('//div[contains(@class, "s-result-list")]//div[@data-index and @data-asin]'):
|
for result in doc.xpath('//div[contains(@class, "s-result-list")]//div[@data-index and @data-asin]'):
|
||||||
kformat = ''.join(result.xpath('.//a[contains(text(), "{}")]//text()'.format(self.KINDLE_EDITION)))
|
kformat = ''.join(result.xpath(f'.//a[contains(text(), "{self.KINDLE_EDITION}")]//text()'))
|
||||||
# Even though we are searching digital-text only Amazon will still
|
# Even though we are searching digital-text only Amazon will still
|
||||||
# put in results for non Kindle books (author pages). So we need
|
# put in results for non Kindle books (author pages). So we need
|
||||||
# to explicitly check if the item is a Kindle book and ignore it
|
# to explicitly check if the item is a Kindle book and ignore it
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
import apsw
|
import apsw
|
||||||
|
@ -845,7 +845,7 @@ class StopException(Exception):
|
|||||||
super().__init__('Template evaluation stopped')
|
super().__init__('Template evaluation stopped')
|
||||||
|
|
||||||
|
|
||||||
class PythonTemplateContext(object):
|
class PythonTemplateContext:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Set attributes we already know must exist.
|
# Set attributes we already know must exist.
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
import os, io
|
import os, io
|
||||||
|
@ -189,7 +189,7 @@ class TestImports(unittest.TestCase):
|
|||||||
if not isbsd:
|
if not isbsd:
|
||||||
exclude_modules.add('calibre.devices.usbms.hal')
|
exclude_modules.add('calibre.devices.usbms.hal')
|
||||||
d = os.path.dirname
|
d = os.path.dirname
|
||||||
SRC = d(d(d((os.path.abspath(__file__)))))
|
SRC = d(d(d(os.path.abspath(__file__))))
|
||||||
self.assertGreater(self.base_check(os.path.join(SRC, 'odf'), exclude_packages, exclude_modules), 10)
|
self.assertGreater(self.base_check(os.path.join(SRC, 'odf'), exclude_packages, exclude_modules), 10)
|
||||||
base = os.path.join(SRC, 'calibre')
|
base = os.path.join(SRC, 'calibre')
|
||||||
self.assertGreater(self.base_check(base, exclude_packages, exclude_modules), 1000)
|
self.assertGreater(self.base_check(base, exclude_packages, exclude_modules), 1000)
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
|
@ -401,7 +401,7 @@ class WinSpeech:
|
|||||||
if DEBUG:
|
if DEBUG:
|
||||||
with suppress(Exception):
|
with suppress(Exception):
|
||||||
print('winspeech:\x1b[31m->\x1b[39m', cmd, flush=True)
|
print('winspeech:\x1b[31m->\x1b[39m', cmd, flush=True)
|
||||||
w.stdin.write(f'{cmd}\n'.encode('utf-8'))
|
w.stdin.write(f'{cmd}\n'.encode())
|
||||||
w.stdin.flush()
|
w.stdin.flush()
|
||||||
return cmd_id
|
return cmd_id
|
||||||
|
|
||||||
|
@ -800,7 +800,7 @@ class BasicNewsRecipe(Recipe):
|
|||||||
`weights`: A dictionary that maps weights to titles. If any titles
|
`weights`: A dictionary that maps weights to titles. If any titles
|
||||||
in index are not in weights, they are assumed to have a weight of 0.
|
in index are not in weights, they are assumed to have a weight of 0.
|
||||||
'''
|
'''
|
||||||
weights = defaultdict(lambda: 0, weights)
|
weights = defaultdict(int, weights)
|
||||||
index.sort(key=lambda x: weights[x])
|
index.sort(key=lambda x: weights[x])
|
||||||
return index
|
return index
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ def serialize_collection(mapping_of_recipe_classes):
|
|||||||
return f'''<?xml version='1.0' encoding='utf-8'?>
|
return f'''<?xml version='1.0' encoding='utf-8'?>
|
||||||
<recipe_collection xmlns="http://calibre-ebook.com/recipe_collection" count="{len(collection)}">
|
<recipe_collection xmlns="http://calibre-ebook.com/recipe_collection" count="{len(collection)}">
|
||||||
{items}
|
{items}
|
||||||
</recipe_collection>'''.encode('utf-8')
|
</recipe_collection>'''.encode()
|
||||||
|
|
||||||
|
|
||||||
def serialize_builtin_recipes():
|
def serialize_builtin_recipes():
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
import json
|
import json
|
||||||
@ -45,8 +44,8 @@ def process_paragraph(lines, block, content_key='content'):
|
|||||||
else:
|
else:
|
||||||
tag = 'p'
|
tag = 'p'
|
||||||
ta = block.get('textAlign') or 'LEFT'
|
ta = block.get('textAlign') or 'LEFT'
|
||||||
style = 'text-align: {}'.format(ta.lower())
|
style = f'text-align: {ta.lower()}'
|
||||||
lines.append('<{} style="{}">'.format(tag, style))
|
lines.append(f'<{tag} style="{style}">')
|
||||||
for item in block[content_key]:
|
for item in block[content_key]:
|
||||||
tn = item['__typename']
|
tn = item['__typename']
|
||||||
if tn in ('TextInline', 'Byline'):
|
if tn in ('TextInline', 'Byline'):
|
||||||
@ -93,7 +92,7 @@ def process_image_block(lines, block):
|
|||||||
if 'web.archive.org' in img:
|
if 'web.archive.org' in img:
|
||||||
img = img.partition('/')[-1]
|
img = img.partition('/')[-1]
|
||||||
img = img[img.find('https://'):]
|
img = img[img.find('https://'):]
|
||||||
lines.append('<div style="text-align: center"><div style="text-align: center"><img src={}/></div><div style="font-size: smaller">'.format(quoteattr(img)))
|
lines.append(f'<div style="text-align: center"><div style="text-align: center"><img src={quoteattr(img)}/></div><div style="font-size: smaller">')
|
||||||
lines.extend(caption_lines)
|
lines.extend(caption_lines)
|
||||||
lines.append('</div></div>')
|
lines.append('</div></div>')
|
||||||
|
|
||||||
@ -181,7 +180,7 @@ def live_json_to_html(data):
|
|||||||
|
|
||||||
def extract_html(soup):
|
def extract_html(soup):
|
||||||
script = soup.findAll('script', text=lambda x: x and 'window.__preloadedData' in x)[0]
|
script = soup.findAll('script', text=lambda x: x and 'window.__preloadedData' in x)[0]
|
||||||
script = type(u'')(script)
|
script = str(script)
|
||||||
raw = script[script.find('{'):script.rfind(';')].strip().rstrip(';')
|
raw = script[script.find('{'):script.rfind(';')].strip().rstrip(';')
|
||||||
return json_to_html(raw)
|
return json_to_html(raw)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user