Skip to content

Commit 6417dd7

Browse files
authored
Merge pull request #42 from huangaszaq/master
add qrcode and dependences
2 parents 287dc32 + af7dae2 commit 6417dd7

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ pycodestyle
55
pylint
66
pylint-quotes
77
pytest
8-
pytype
8+
pytype==2020.2.20
99
semver

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
requests
2+
qrcode

src/wechaty/utils/qrcode_terminal.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import qrcode
2+
import platform
3+
4+
5+
def qr_terminal_str(data,version=None):
6+
"""
7+
8+
:param data: qrcode data
9+
:param version:1-40 or None
10+
:return:
11+
"""
12+
if platform.system() == "Windows":
13+
white_block = '▇'
14+
black_block = ' '
15+
new_line = '\n'
16+
else:
17+
white_block = '\033[0;37;47m '
18+
black_block = '\033[0;37;40m '
19+
new_line = '\033[0m\n'
20+
21+
qr = qrcode.QRCode(version)
22+
qr.add_data(data)
23+
if version:
24+
qr.make()
25+
else:
26+
qr.make(fit=True)
27+
output = white_block*(qr.modules_count+2) + new_line
28+
for mn in qr.modules:
29+
output += white_block
30+
for m in mn:
31+
if m:
32+
output += black_block
33+
else:
34+
output += white_block
35+
output += white_block + new_line
36+
output += white_block*(qr.modules_count+2) + new_line
37+
return output
38+
39+
40+
def draw(data, version=None):
41+
output = qr_terminal_str(data,version)
42+
print (output)

0 commit comments

Comments
 (0)