diff --git a/requirements-dev.txt b/requirements-dev.txt index 0996e999..55a209c4 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,5 +5,5 @@ pycodestyle pylint pylint-quotes pytest -pytype +pytype==2020.2.20 semver diff --git a/requirements.txt b/requirements.txt index f2293605..f493840a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ requests +qrcode diff --git a/src/wechaty/utils/qrcode_terminal.py b/src/wechaty/utils/qrcode_terminal.py new file mode 100644 index 00000000..ed1fbdff --- /dev/null +++ b/src/wechaty/utils/qrcode_terminal.py @@ -0,0 +1,42 @@ +import qrcode +import platform + + +def qr_terminal_str(data,version=None): + """ + + :param data: qrcode data + :param version:1-40 or None + :return: + """ + if platform.system() == "Windows": + white_block = '▇' + black_block = ' ' + new_line = '\n' + else: + white_block = '\033[0;37;47m ' + black_block = '\033[0;37;40m ' + new_line = '\033[0m\n' + + qr = qrcode.QRCode(version) + qr.add_data(data) + if version: + qr.make() + else: + qr.make(fit=True) + output = white_block*(qr.modules_count+2) + new_line + for mn in qr.modules: + output += white_block + for m in mn: + if m: + output += black_block + else: + output += white_block + output += white_block + new_line + output += white_block*(qr.modules_count+2) + new_line + return output + + +def draw(data, version=None): + output = qr_terminal_str(data,version) + print (output)