#!/usr/bin/env python3 import qrcode def print_qr_unicode(qr): matrix = qr.get_matrix() # Render two rows per terminal line using half-block characters. for i in range(0, len(matrix), 2): row_top = matrix[i] row_bottom = matrix[i + 1] if i + 1 < len(matrix) else [False] * len(row_top) line = [] for top, bottom in zip(row_top, row_bottom): if top and bottom: line.append("█") elif top and not bottom: line.append("▀") elif not top and bottom: line.append("▄") else: line.append(" ") print("".join(line)) secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # Use the secret generated in the previous step (the Base64-encoded string) uri = "otpauth://totp/infomaniak-public-cloud?secret={}&issuer=Keystone".format(secret) qr = qrcode.QRCode(border=2) qr.add_data(uri) qr.make(fit=True) img = qr.make_image() img.save("totp.png") print( "Saved QR code image to totp.png (use this if your terminal can't render the blocks)." ) print_qr_unicode(qr)