Created
September 26, 2014 08:03
QRcode generator for the access local test server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
QRcode generator | |
usage: | |
qr_gen.py [-t] <url> | |
options: | |
-t Translate localhost or loopback address to host address | |
""" | |
import qrcode | |
import re | |
import socket | |
from docopt import docopt | |
if __name__ == '__main__': | |
args = docopt(__doc__) | |
url = url_r = args['<url>'] | |
if args['-t']: | |
expr = re.compile(r'^(https?://)(localhost|127\.0\.0\.1)') | |
repl = r'\g<1>' + socket.gethostbyname(socket.gethostname()) | |
url_r = expr.sub(repl, url) | |
if url != url_r: | |
print('%s => %s' % (url, url_r)) | |
else: | |
print(url) | |
img = qrcode.make(url_r) | |
img.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment