1. 重构快手
- 图文增加 - 封面增加 2. 快手skill,cli支持
This commit is contained in:
+8
-2
@@ -1,10 +1,16 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from sys import stdout
|
||||
from loguru import logger
|
||||
|
||||
from conf import BASE_DIR
|
||||
|
||||
|
||||
if hasattr(sys.stdout, "reconfigure"):
|
||||
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
||||
if hasattr(sys.stderr, "reconfigure"):
|
||||
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
|
||||
|
||||
|
||||
def log_formatter(record: dict) -> str:
|
||||
"""
|
||||
Formatter for log records.
|
||||
@@ -41,7 +47,7 @@ def create_logger(log_name: str, file_path: str):
|
||||
# Remove all existing handlers
|
||||
logger.remove()
|
||||
# Add a standard console handler
|
||||
logger.add(stdout, colorize=True, format=log_formatter)
|
||||
logger.add(sys.stdout, colorize=True, format=log_formatter)
|
||||
|
||||
douyin_logger = create_logger('douyin', 'logs/douyin.log')
|
||||
tencent_logger = create_logger('tencent', 'logs/tencent.log')
|
||||
|
||||
@@ -57,14 +57,20 @@ def _print_ascii_qrcode(qrcode) -> None:
|
||||
print(empty_line)
|
||||
|
||||
|
||||
def print_terminal_qrcode(qrcode_content: str, qrcode_path: Path, app_name: str) -> None:
|
||||
def print_terminal_qrcode(
|
||||
qrcode_content: str,
|
||||
qrcode_path: Path,
|
||||
app_name: str,
|
||||
compact: bool = True,
|
||||
border: int = 0,
|
||||
) -> None:
|
||||
print()
|
||||
print(f"请使用{app_name}扫描下方二维码登录:")
|
||||
qrcode = segno.make(qrcode_content, error="L", boost_error=False)
|
||||
try:
|
||||
if hasattr(sys.stdout, "reconfigure"):
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
qrcode.terminal(compact=True, border=0)
|
||||
qrcode.terminal(compact=compact, border=border)
|
||||
except (UnicodeEncodeError, OSError):
|
||||
print("当前终端不支持 Unicode 二维码字符,已切换为 ASCII 打印:")
|
||||
_print_ascii_qrcode(qrcode)
|
||||
|
||||
Reference in New Issue
Block a user