Skip to content

Instantly share code, notes, and snippets.

@jason-green-io
Created April 5, 2019 02:20
Show Gist options
  • Save jason-green-io/ed2dc763aed74756d1abd2135fe55d8c to your computer and use it in GitHub Desktop.
Save jason-green-io/ed2dc763aed74756d1abd2135fe55d8c to your computer and use it in GitHub Desktop.
a little helper function to be used with qrcode to print compact QR codes in terminal using a custom font and Unicode EE00-EEFF
from collections import defaultdict
import qrcode
a = [[0, 1, 1, 1, 0, 1, 0],
[1, 0, 0, 0, 1, 1, 0],
[0, 1, 1, 1, 0, 1, 0],
[0, 1, 1, 1, 0, 1, 0],
[0, 1, 1, 1, 0, 1, 0],
[0, 1, 1, 1, 0, 1, 0],
[0, 1, 1, 1, 0, 1, 0]]
map = [[1,8],
[2,16],
[4,32],
[64,128]]
data = "does this work? and if so, how big could I make this text? do large QRcodes still fit on the screen? .. is this text way too big?"
brailledecimal = 10240
qrdecimal = 60928
def qrunicode(data):
code = qrcode.QRCode()
code.add_data(data)
code.border=1
matrix = code.get_matrix()
chars = defaultdict(int)
for y, r in enumerate(matrix):
yc, ymap = divmod(y, 4)
ymax = yc
for x, b in enumerate(r):
xc, xmap = divmod(x, 2)
xmax = xc
if b:
chars[yc,xc] += map[ymap][xmap]
stringList = []
for y in range(0, ymax + 1):
string = ""
for x in range(0, xmax + 1):
string += chr(qrdecimal + chars[y, x])
stringList.append(string)
return "\n".join(stringList)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment