generating qr codes and serving them as images
This commit is contained in:
Executable
BIN
Binary file not shown.
@@ -1,10 +1,14 @@
|
|||||||
from flask import Flask, Response, redirect, url_for, request, session, abort, render_template
|
from flask import Flask, Response, redirect, url_for, request, session, abort, render_template, send_file
|
||||||
from flask_login import LoginManager, UserMixin, login_required, login_user, logout_user, current_user
|
from flask_login import LoginManager, UserMixin, login_required, login_user, logout_user, current_user
|
||||||
|
from PIL import Image, ImageFont, ImageDraw
|
||||||
|
from io import BytesIO
|
||||||
|
import qrcode
|
||||||
import json
|
import json
|
||||||
import datetime
|
|
||||||
import re
|
import re
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
systemURL = 'http://192.168.0.11:5000/'
|
||||||
|
|
||||||
with open('links.json', 'r') as infile:
|
with open('links.json', 'r') as infile:
|
||||||
links = json.load(infile)
|
links = json.load(infile)
|
||||||
|
|
||||||
@@ -23,6 +27,20 @@ def codeLink(code):
|
|||||||
return None
|
return None
|
||||||
return links[code]['url']
|
return links[code]['url']
|
||||||
|
|
||||||
|
def serveImage(img):
|
||||||
|
img_io = BytesIO()
|
||||||
|
img.save(img_io, 'PNG')
|
||||||
|
img_io.seek(0)
|
||||||
|
return send_file(img_io, mimetype='image/png')
|
||||||
|
|
||||||
|
@app.route('/code/<code>')
|
||||||
|
def serveCode(code):
|
||||||
|
code = code[:code.find('.')]
|
||||||
|
if codeValidation(code) is False:
|
||||||
|
return send_file('static/invalid.png', mimetype='image/png')
|
||||||
|
img = qrcode.make(systemURL + code)
|
||||||
|
return serveImage(img)
|
||||||
|
|
||||||
@app.route("/edit", methods=['GET', 'POST'])
|
@app.route("/edit", methods=['GET', 'POST'])
|
||||||
def edit():
|
def edit():
|
||||||
code = request.form.get("code")
|
code = request.form.get("code")
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ Python, and the following packages:
|
|||||||
* flask
|
* flask
|
||||||
* flask-login
|
* flask-login
|
||||||
* qrcode
|
* qrcode
|
||||||
|
* pillow
|
||||||
|
|
||||||
##Work in progress
|
##Work in progress
|
||||||
The system is currently under initial development, and is **not** operational.
|
The system is currently under initial development, and is **not** operational.
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 76 KiB |
Reference in New Issue
Block a user