Project
Function
Sample CLI
gway qr generate-url
References
['resource']
Full Code
def generate_url(value):
"""Return the local URL to a QR code with the given value.
This will only work when the website is up and running to serve /work
This generates a new QR code image if needed, or uses a cache if possible.
"""
safe_filename = base64.urlsafe_b64encode(value.encode("utf-8")).decode("ascii").rstrip("=") + ".png"
if safe_filename not in _qr_code_cache:
qr_path = gw.resource("work", "shared", "qr_codes", safe_filename)
if not os.path.exists(qr_path):
generate_image(value, path=qr_path)
_qr_code_cache.add(safe_filename)
return f"/work/qr-codes/{safe_filename}"