feat: Add stdout from process to the template

This commit is contained in:
Cristian 2020-07-01 12:23:59 -05:00
parent bc1f925542
commit c971e00c9c
4 changed files with 276 additions and 208 deletions
archivebox

View file

@ -20,6 +20,7 @@ from .config import (
CHECK_SSL_VALIDITY,
WGET_USER_AGENT,
CHROME_OPTIONS,
COLOR_DICT
)
try:
@ -69,6 +70,8 @@ URL_REGEX = re.compile(
re.IGNORECASE,
)
COLOR_REGEX = re.compile(r'\[(?P<arg_1>\d+)(;(?P<arg_2>\d+)(;(?P<arg_3>\d+))?)?m')
def enforce_types(func):
"""
@ -195,6 +198,27 @@ def chrome_args(**options) -> List[str]:
return cmd_args
def ansi_to_html(text):
"""
Based on: https://stackoverflow.com/questions/19212665/python-converting-ansi-color-codes-to-html
"""
TEMPLATE = '<span style="color: rgb{}"><br>'
text = text.replace('[m', '</span>')
def single_sub(match):
argsdict = match.groupdict()
if argsdict['arg_3'] is None:
if argsdict['arg_2'] is None:
bold, color = 0, argsdict['arg_1']
else:
bold, color = argsdict['arg_1'], argsdict['arg_2']
else:
bold, color = argsdict['arg_3'], argsdict['arg_2']
return TEMPLATE.format(COLOR_DICT[color][0])
return COLOR_REGEX.sub(single_sub, text)
class ExtendedEncoder(pyjson.JSONEncoder):
"""