处理format空格对齐内容包含中文的情况,DEBUG INFO输出对齐

This commit is contained in:
lededev
2022-04-12 06:34:08 +08:00
parent 9a3b48140d
commit 475f02fbe6
2 changed files with 14 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry from urllib3.util.retry import Retry
from cloudscraper import create_scraper from cloudscraper import create_scraper
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from unicodedata import category
def getXpathSingle(htmlcode, xpath): def getXpathSingle(htmlcode, xpath):
@@ -566,6 +567,7 @@ def delete_all_elements_in_list(string: str, lists: typing.Iterable[str]):
new_lists.append(i) new_lists.append(i)
return new_lists return new_lists
def delete_all_elements_in_str(string_delete: str, string: str): def delete_all_elements_in_str(string_delete: str, string: str):
""" """
delete same string in given list delete same string in given list
@@ -573,4 +575,14 @@ def delete_all_elements_in_str(string_delete: str, string: str):
for i in string: for i in string:
if i == string_delete: if i == string_delete:
string = string.replace(i,"") string = string.replace(i,"")
return string return string
def cnspace(v: str, n: int) -> int:
"""
print format空格填充对齐内容包含中文时的空格计算
"""
cw = 0
for c in v:
cw += 1 if category(c) in ('Lo',) else 0
return n - cw

View File

@@ -608,7 +608,7 @@ def debug_print(data: json):
if i == 'extrafanart': if i == 'extrafanart':
print('[+] -', "%-14s" % i, ':', len(v), 'links') print('[+] -', "%-14s" % i, ':', len(v), 'links')
continue continue
print('[+] -', "%-14s" % i, ':', v) print(f'[+] - {i:<{cnspace(i,14)}} : {v}')
print("[+] ------- DEBUG INFO -------") print("[+] ------- DEBUG INFO -------")
except: except: