Improve processing custom emojis
This commit is contained in:
@@ -3,6 +3,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
from base64 import standard_b64encode
|
from base64 import standard_b64encode
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from .chat_processor import ChatProcessor
|
from .chat_processor import ChatProcessor
|
||||||
from .default.processor import DefaultProcessor
|
from .default.processor import DefaultProcessor
|
||||||
from ..exceptions import UnknownConnectionError
|
from ..exceptions import UnknownConnectionError
|
||||||
@@ -54,6 +55,7 @@ class HTMLArchiver(ChatProcessor):
|
|||||||
self.header = [HEADER_HTML]
|
self.header = [HEADER_HTML]
|
||||||
self.body = ['<body>\n', '<table class="css">\n', self._parse_table_header(fmt_headers)]
|
self.body = ['<body>\n', '<table class="css">\n', self._parse_table_header(fmt_headers)]
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
|
self.executor = ThreadPoolExecutor(max_workers=10)
|
||||||
|
|
||||||
def _checkpath(self, filepath):
|
def _checkpath(self, filepath):
|
||||||
splitter = os.path.splitext(os.path.basename(filepath))
|
splitter = os.path.splitext(os.path.basename(filepath))
|
||||||
@@ -80,7 +82,7 @@ class HTMLArchiver(ChatProcessor):
|
|||||||
save_path : str :
|
save_path : str :
|
||||||
Actual save path of file.
|
Actual save path of file.
|
||||||
total_lines : int :
|
total_lines : int :
|
||||||
count of total lines written to the file.
|
Count of total lines written to the file.
|
||||||
"""
|
"""
|
||||||
if chat_components is None or len(chat_components) == 0:
|
if chat_components is None or len(chat_components) == 0:
|
||||||
return
|
return
|
||||||
@@ -132,7 +134,7 @@ class HTMLArchiver(ChatProcessor):
|
|||||||
def _set_emoji_table(self, item: dict):
|
def _set_emoji_table(self, item: dict):
|
||||||
emoji_id = item['id']
|
emoji_id = item['id']
|
||||||
if emoji_id not in self.emoji_table:
|
if emoji_id not in self.emoji_table:
|
||||||
self.emoji_table.setdefault(emoji_id, self._encode_img(item['url']))
|
self.emoji_table.setdefault(emoji_id, self.executor.submit(self._encode_img, item['url']))
|
||||||
return emoji_id
|
return emoji_id
|
||||||
|
|
||||||
def _stylecode(self, name, code, width, height):
|
def _stylecode(self, name, code, width, height):
|
||||||
@@ -143,11 +145,12 @@ class HTMLArchiver(ChatProcessor):
|
|||||||
def _create_styles(self):
|
def _create_styles(self):
|
||||||
return '\n'.join(('<style type="text/css">',
|
return '\n'.join(('<style type="text/css">',
|
||||||
TABLE_CSS,
|
TABLE_CSS,
|
||||||
'\n'.join(self._stylecode(key, self.emoji_table[key], 24, 24)
|
'\n'.join(self._stylecode(key, self.emoji_table[key].result(), 24, 24)
|
||||||
for key in self.emoji_table.keys()),
|
for key in self.emoji_table.keys()),
|
||||||
'</style>\n'))
|
'</style>\n'))
|
||||||
|
|
||||||
def finalize(self):
|
def finalize(self):
|
||||||
|
self.executor.shutdown()
|
||||||
self.header.extend([self._create_styles(), '</head>\n'])
|
self.header.extend([self._create_styles(), '</head>\n'])
|
||||||
self.body.extend(['</table>\n</body>\n</html>'])
|
self.body.extend(['</table>\n</body>\n</html>'])
|
||||||
with open(self.save_path, mode='a', encoding='utf-8') as f:
|
with open(self.save_path, mode='a', encoding='utf-8') as f:
|
||||||
|
|||||||
Reference in New Issue
Block a user