-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
32 lines (25 loc) · 784 Bytes
/
main.py
File metadata and controls
32 lines (25 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import io
import os
from flask import Flask, request, send_file
import qrcode
application = Flask(__name__)
def generate_qr(url):
qr = qrcode.QRCode(version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4)
qr.add_data(url)
qr.make(fit=True)
img = qr.make_image()
return img
@application.route("/")
def r_qrcode():
url = request.args.get('url', default='https://www.google.com')
img_buf = io.BytesIO()
img = generate_qr(url)
img.save(img_buf)
img_buf.seek(0)
return send_file(img_buf, mimetype='image/png')
# run the app.
if __name__ == "__main__":
application.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))