aboutsummaryrefslogtreecommitdiff
path: root/SimplyQrGen.py
diff options
context:
space:
mode:
Diffstat (limited to 'SimplyQrGen.py')
-rw-r--r--SimplyQrGen.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/SimplyQrGen.py b/SimplyQrGen.py
new file mode 100644
index 0000000..53f7c7d
--- /dev/null
+++ b/SimplyQrGen.py
@@ -0,0 +1,33 @@
+from qrcodegen import QrCode, QrSegment
+import sys
+
+def print_usage():
+ """Print the usage help."""
+ print("Usage:")
+ print(sys.argv[0] + " <text to put in qrcode>")
+
+def gen_qr(text):
+ """Gen the QR Code based on the given text."""
+ return QrCode.encode_text(text, QrCode.Ecc.LOW)
+
+def print_qr(qrcode):
+ """Prints the given QrCode object to the console."""
+ border = 4
+ for y in range(-border, qrcode.get_size() + border):
+ for x in range(-border, qrcode.get_size() + border):
+ print(u"\u2588 "[1 if qrcode.get_module(x,y) else 0] * 2, end="")
+ print()
+ print()
+
+def main():
+ """The main application program."""
+ if len(sys.argv) == 2:
+ if sys.argv[1] != "":
+ print_qr(gen_qr(sys.argv[1]))
+ else:
+ print_usage()
+ else:
+ print_usage()
+
+if __name__ == "__main__":
+ main()