From 60947adc1a7493f1a113d130d02d4a51f9cc54c5 Mon Sep 17 00:00:00 2001 From: yanzhehao Date: Thu, 15 Aug 2019 15:31:31 +0800 Subject: [PATCH] issue #792 --- itchat/utils.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/itchat/utils.py b/itchat/utils.py index e217368c..ddc5376b 100644 --- a/itchat/utils.py +++ b/itchat/utils.py @@ -18,14 +18,6 @@ emojiRegex = re.compile(r'') htmlParser = HTMLParser() -try: - b = u'\u2588' - sys.stdout.write(b + '\r') - sys.stdout.flush() -except UnicodeEncodeError: - BLOCK = 'MM' -else: - BLOCK = b friendInfoTemplate = {} for k in ('UserName', 'City', 'DisplayName', 'PYQuanPin', 'RemarkPYInitial', 'Province', 'KeyWord', 'RemarkName', 'PYInitial', 'EncryChatRoomId', 'Alias', 'Signature', @@ -40,6 +32,17 @@ def clear_screen(): os.system('cls' if config.OS == 'Windows' else 'clear') +def get_BLOCK(): + try: + b = u'\u2588' + sys.stdout.write(b + '\r') + sys.stdout.flush() + except UnicodeEncodeError: + BLOCK = 'MM' + else: + BLOCK = b + return BLOCK + def emoji_formatter(d, k): ''' _emoji_deebugger is for bugs about emoji match caused by wechat backstage like :face with tears of joy: will be replaced with :cat face with tears of joy: @@ -89,7 +92,9 @@ def print_qr(fileDir): else: os.startfile(fileDir) -def print_cmd_qr(qrText, white=BLOCK, black=' ', enableCmdQR=True): +def print_cmd_qr(qrText, white=None, black=' ', enableCmdQR=True): + if white == None: + white = get_BLOCK() blockCount = int(enableCmdQR) if abs(blockCount) == 0: blockCount = 1