Generating pritable labels

This commit is contained in:
2018-10-17 15:14:02 +02:00
parent 5d6db5aea5
commit 4176c1afcd
4 changed files with 65 additions and 5 deletions
+20 -4
View File
@@ -6,7 +6,8 @@ from io import BytesIO
import json, random, re, string
app = Flask(__name__)
systemURL = 'http://192.168.0.11:5000/'
systemURL = 'http://192.168.0.11:5000/' #FULL URL with a '/' at the end
systemURL = 'http://10.0.1.115:5000/'
randomchars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789' #note the lack of zero
with open('links.json', 'r') as infile:
@@ -23,7 +24,7 @@ def randomToken():
return code
def codeValidation(code):
if len(code) not in range (5,6):
if len(code) not in range (3,10):
return False
if re.match('^[\w-]+$', code) is None:
return False
@@ -55,7 +56,15 @@ 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)
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_M,
box_size=8,
border=3,
)
qr.add_data('systemURL + code')
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
return serveImage(img)
@app.route("/edit", methods=['GET', 'POST'])
@@ -87,7 +96,14 @@ def generate():
howmany = request.form.get("howmany")
if howmany is None:
return render_template('generate.html')
return render_template("message.html", message="Totally generated {} many codes right now.".format(howmany))
codes = []
for i in range(0, int(howmany)):
codes.append(createNewCode())
columns = 4
codesarray = [codes[i:i+columns] for i in range(0, len(codes), columns)]
saveFile()
humanSystemURL = systemURL[systemURL.find('//')+2:]
return render_template("printlabels.html", codes=codesarray, systemURL=humanSystemURL, codegenURL=systemURL+'code/', format='.png')
@app.route("/list")
def list():