Skip to content

Commit

Permalink
fix send_to_kindle crash and minor improve dict
Browse files Browse the repository at this point in the history
  • Loading branch information
cdhigh committed Nov 24, 2024
1 parent 8e2164d commit d5784ed
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 177 deletions.
20 changes: 12 additions & 8 deletions application/lib/build_ebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def convert_book(input_, input_fmt, user, options=None, output_fmt=''):
return b''

#仅通过一个url列表构建一本电子书
#urls: [(title, url),...] or [url,url,...]
#urls: [(title, url),...] or [url, url,...]
#title: 书籍标题
#user: KeUser对象
#output_fmt: 如果指定,则生成特定格式的书籍,否则使用 user.book_cfg('type')
Expand All @@ -49,29 +49,33 @@ def clearPrevDownloads(): #退出时清理临时文件
print(f'Delete failed: {item}: {e}')
pass

for idx, url in enumerate(urls[:]):
if not sysTmpDir or not isinstance(url, str): #如果没有使用临时目录则无法提取下载
urls[idx] = (title, url) if isinstance(url, str) else url
titleUrls = urls[:]
#规整化urls列表元素格式,同时预下载文章内容,提取文章的标题
#这一步主要是能让每篇文章都使用真实的标题
for idx, url in enumerate(titleUrls):
#如果没有使用临时目录则无法提取下载
if not sysTmpDir or not isinstance(url, str):
titleUrls[idx] = (title, url) if isinstance(url, str) else url
continue

resp = UrlOpener().open(url)
if resp.status_code != 200:
urls[idx] = (title, url)
titleUrls[idx] = (title, url)
continue

with PersistentTemporaryFile(suffix='.html', dir=sysTmpDir) as pt:
prevDownloads.append(pt.name)
try:
pt.write(resp.content)
except Exception as e:
urls[idx] = (title, url)
titleUrls[idx] = (title, url)
default_log.warning(f'Prev download html failed: {url}: {e}')
else: #提取标题
match = re.search(r'<title[^>]*>(.*?)</title>', resp.text, re.I|re.M|re.S)
uTitle = match.group(1).strip() if match else title
urls[idx] = (uTitle, 'file://' + pt.name)
titleUrls[idx] = (uTitle, 'file://' + pt.name)

src = GenerateRecipeSource(title, urls, user, base='UrlNewsRecipe', max_articles=100,
src = GenerateRecipeSource(title, titleUrls, user, base='UrlNewsRecipe', max_articles=100,
cover_url=False, language=language)
try:
ro = compile_recipe(src)
Expand Down
2 changes: 1 addition & 1 deletion application/lib/dictionary/babylon/babylon_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, database='', host=None):
self.initError = loc_exc_pos(f'Init BabylonDict failed: {self.databases[database]}')
default_log.warning(self.initError)
else:
self.initError = f'Dict not found: {self.databases[database]}'
self.initError = f'Dict not found: {database}'
default_log.warning(self.initError)

#返回当前使用的词典名字
Expand Down
2 changes: 1 addition & 1 deletion application/lib/dictionary/lingvo/lingvo_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, database='', host=None):
self.initError = loc_exc_pos(f'Init LingvoDict failed: {self.databases[database]}')
default_log.warning(self.initError)
else:
self.initError = f'Dict not found: {self.databases[database]}'
self.initError = f'Dict not found: {database}'
default_log.warning(self.initError)

#返回当前使用的词典名字
Expand Down
2 changes: 1 addition & 1 deletion application/lib/dictionary/mdict/mdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, database='', host=None):
self.initError = loc_exc_pos(f'Init mdict failed: {self.databases[database]}')
default_log.warning(self.initError)
else:
self.initError = f'Dict not found: {self.databases[database]}'
self.initError = f'Dict not found: {database}'
default_log.warning(self.initError)

#返回当前使用的词典名字
Expand Down
2 changes: 1 addition & 1 deletion application/lib/dictionary/stardict/stardict.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, database='', host=None):
self.initError = loc_exc_pos(f'Init stardict failed: {self.databases[database]}')
default_log.warning(self.initError)
else:
self.initError = f'Dict not found: {self.databases[database]}'
self.initError = f'Dict not found: {database}'
default_log.warning(self.initError)

#返回当前使用的词典名字
Expand Down
5 changes: 4 additions & 1 deletion application/static/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1728,9 +1728,12 @@ function DictEngineFieldChanged(idx) {
var engine = engineSel.val();
dbSel.empty();
var databases = g_dictEngines[engine].databases;
if (!databases) {
if (!databases || Object.keys(databases).length === 0) {
var txt = `<option value="${name}" ${selected}>${databases[name]}</option>`;
dbSel.append($(`<option value="" disabled selected>[${i18n.putFileInDict}]</option>`));
return;
}

var currDb = g_dictParams[idx].database;
for (var name in databases) {
var selected = (currDb == name) ? 'selected="selected"' : '';
Expand Down
3 changes: 2 additions & 1 deletion application/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@
weekday: "{{_('Weekday')|safe}}",
date: "{{_('Date')|safe}}",
settingIsPrioritized: "{{_('This setting is prioritized.')|safe}}",
multiValuesWithCommas: "{{_('Combine multiple values with commas.')}}"
multiValuesWithCommas: "{{_('Combine multiple values with commas.')}}",
putFileInDict: "{{_('Put dictionary in dict folder')}}"
};
</script>
{% block javascript_inhead %}
Expand Down
112 changes: 58 additions & 54 deletions application/translations/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-11-21 10:11-0300\n"
"POT-Creation-Date: 2024-11-23 21:29-0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -17,7 +17,7 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.14.0\n"

#: application/templates/admin.html:3 application/templates/base.html:182
#: application/templates/admin.html:3 application/templates/base.html:183
#: application/templates/settings.html:252
msgid "Admin"
msgstr ""
Expand Down Expand Up @@ -252,31 +252,31 @@ msgid "Dictionary"
msgstr ""

#: application/templates/adv_base.html:75
#: application/templates/adv_base.html:79
#: application/templates/adv_base.html:83
#: application/templates/adv_proxy.html:3
#: application/templates/adv_proxy.html:12
msgid "Proxy"
msgstr ""

#: application/templates/adv_base.html:92
#: application/templates/adv_base.html:96
#: application/templates/adv_import.html:8
msgid "Import Feeds"
msgstr ""

#: application/templates/adv_base.html:84
#: application/templates/adv_base.html:88
#: application/templates/adv_base.html:101
#: application/templates/adv_base.html:105
msgid "Cover Image"
msgstr ""

#: application/templates/adv_base.html:93
#: application/templates/adv_base.html:97
#: application/templates/adv_base.html:110
#: application/templates/adv_base.html:114
#: application/templates/adv_uploadcss.html:3
msgid "Stylesheet"
msgstr ""

#: application/templates/adv_base.html:102
#: application/templates/adv_base.html:106
#: application/templates/adv_proxy.html:3
#: application/templates/adv_proxy.html:12
msgid "Proxy"
msgstr ""

#: application/templates/adv_base.html:111
#: application/templates/adv_base.html:115
#: application/templates/adv_base.html:119
#: application/templates/adv_base.html:123
#: application/templates/adv_calibre_options.html:12
msgid "Calibre Options"
msgstr ""
Expand Down Expand Up @@ -954,43 +954,47 @@ msgstr ""
msgid "Combine multiple values with commas."
msgstr ""

#: application/templates/base.html:155 application/templates/home.html:16
#: application/templates/base.html:131
msgid "Put dictionary in dict folder"
msgstr ""

#: application/templates/base.html:156 application/templates/home.html:16
msgid "Logout"
msgstr ""

#: application/templates/base.html:157 application/templates/home.html:21
#: application/templates/base.html:158 application/templates/home.html:21
#: application/templates/login.html:3 application/templates/login.html:22
#: application/templates/login.html:33
msgid "Login"
msgstr ""

#: application/templates/base.html:159 application/templates/signup.html:3
#: application/templates/base.html:160 application/templates/signup.html:3
#: application/templates/signup.html:19 application/templates/signup.html:43
msgid "Signup"
msgstr ""

#: application/templates/base.html:179 application/templates/home.html:15
#: application/templates/base.html:180 application/templates/home.html:15
#: application/templates/my.html:3
msgid "Feeds"
msgstr ""

#: application/templates/base.html:180 application/templates/settings.html:3
#: application/templates/base.html:181 application/templates/settings.html:3
msgid "Settings"
msgstr ""

#: application/templates/base.html:181 application/templates/logs.html:3
#: application/templates/base.html:182 application/templates/logs.html:3
msgid "Logs"
msgstr ""

#: application/templates/base.html:183
#: application/templates/base.html:184
msgid "Advanced"
msgstr ""

#: application/templates/base.html:184 application/templates/library.html:3
#: application/templates/base.html:185 application/templates/library.html:3
msgid "Shared"
msgstr ""

#: application/templates/base.html:185 application/templates/reader.html:6
#: application/templates/base.html:186 application/templates/reader.html:6
msgid "Reader"
msgstr ""

Expand Down Expand Up @@ -1684,8 +1688,8 @@ msgstr ""
msgid "Word"
msgstr ""

#: application/view/admin.py:48 application/view/adv.py:431
#: application/view/adv.py:483 application/view/settings.py:66
#: application/view/admin.py:48 application/view/adv.py:434
#: application/view/adv.py:486 application/view/settings.py:66
#: application/view/translator.py:87 application/view/translator.py:171
#: application/view/translator.py:253
msgid "Settings Saved!"
Expand Down Expand Up @@ -1740,93 +1744,93 @@ msgstr ""
msgid "Changes saved successfully."
msgstr ""

#: application/view/adv.py:101 application/view/adv.py:102
#: application/view/adv.py:103 application/view/adv.py:104
#: application/view/adv.py:105 application/view/adv.py:106
#: application/view/adv.py:107 application/view/adv.py:108
#: application/view/adv.py:109 application/view/adv.py:110
#: application/view/adv.py:104 application/view/adv.py:105
#: application/view/adv.py:106 application/view/adv.py:107
#: application/view/adv.py:108 application/view/adv.py:109
#: application/view/adv.py:110 application/view/adv.py:111
#: application/view/adv.py:112 application/view/adv.py:113
msgid "Append hyperlink '{}' to article"
msgstr ""

#: application/view/adv.py:101 application/view/adv.py:102
#: application/view/adv.py:103 application/view/adv.py:104
#: application/view/adv.py:105
#: application/view/adv.py:104 application/view/adv.py:105
#: application/view/adv.py:106 application/view/adv.py:107
#: application/view/adv.py:108
msgid "Save to {}"
msgstr ""

#: application/view/adv.py:101
#: application/view/adv.py:104
msgid "evernote"
msgstr ""

#: application/view/adv.py:102
#: application/view/adv.py:105
msgid "wiz"
msgstr ""

#: application/view/adv.py:103
#: application/view/adv.py:106
msgid "pocket"
msgstr ""

#: application/view/adv.py:104
#: application/view/adv.py:107
msgid "instapaper"
msgstr ""

#: application/view/adv.py:105
#: application/view/adv.py:108
msgid "wallabag"
msgstr ""

#: application/view/adv.py:106 application/view/adv.py:107
#: application/view/adv.py:108 application/view/adv.py:109
#: application/view/adv.py:109 application/view/adv.py:110
#: application/view/adv.py:111 application/view/adv.py:112
msgid "Share on {}"
msgstr ""

#: application/view/adv.py:106
#: application/view/adv.py:109
msgid "weibo"
msgstr ""

#: application/view/adv.py:107
#: application/view/adv.py:110
msgid "facebook"
msgstr ""

#: application/view/adv.py:109
#: application/view/adv.py:112
msgid "tumblr"
msgstr ""

#: application/view/adv.py:110
#: application/view/adv.py:113
msgid "Open in browser"
msgstr ""

#: application/view/adv.py:111
#: application/view/adv.py:114
msgid "Append qrcode of url to article"
msgstr ""

#: application/view/adv.py:375 application/view/share.py:54
#: application/view/adv.py:378 application/view/share.py:54
#: application/view/subscribe.py:250
msgid "Unknown command: {}"
msgstr ""

#: application/view/adv.py:433 application/view/adv.py:485
#: application/view/adv.py:436 application/view/adv.py:488
msgid "The format is invalid."
msgstr ""

#: application/view/adv.py:517
#: application/view/adv.py:520
msgid "Authorization Error!<br/>{}"
msgstr ""

#: application/view/adv.py:538
#: application/view/adv.py:541
msgid "Success authorized by Pocket!"
msgstr ""

#: application/view/adv.py:544
#: application/view/adv.py:547
msgid ""
"Failed to request authorization of Pocket!<hr/>See details "
"below:<br/><br/>{}"
msgstr ""

#: application/view/adv.py:565
#: application/view/adv.py:568
msgid "The Instapaper service encountered an error. Please try again later."
msgstr ""

#: application/view/adv.py:578
#: application/view/adv.py:581
msgid "Request type [{}] unsupported"
msgstr ""

Expand Down
Binary file modified application/translations/tr_TR/LC_MESSAGES/messages.mo
Binary file not shown.
Loading

0 comments on commit d5784ed

Please sign in to comment.