Skip to content

Commit

Permalink
Merge pull request #42 from huangaszaq/master
Browse files Browse the repository at this point in the history
add qrcode and dependences
  • Loading branch information
wj-Mcat authored Apr 30, 2020
2 parents 287dc32 + af7dae2 commit 6417dd7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ pycodestyle
pylint
pylint-quotes
pytest
pytype
pytype==2020.2.20
semver
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
requests
qrcode
42 changes: 42 additions & 0 deletions src/wechaty/utils/qrcode_terminal.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 6417dd7

Please sign in to comment.