rework barcode generator

This commit is contained in:
Pavol Rusnak 2011-06-14 18:47:04 +02:00
parent 0b488c469c
commit 834b7a4959
3 changed files with 28 additions and 27 deletions

View file

@ -8,38 +8,27 @@ import sys
svghead = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="1052.3622" height="744.09448" version="1.1" id="svg2" inkscape:version="0.47 r22583" sodipodi:docname="barcodes.svg">
"""
svgfoot = """
</svg>
svgfoot = """</svg>
"""
width = 4
scalex = 1.2
scaley = 1.2
f = open('../dos/people.txt','r')
items = f.readlines()
f.close()
items = map(lambda x: x.strip(), items)
itemss = map(lambda x: x[0:3], items)
f = open('../dos/items.txt','r')
for l in f.readlines():
l = l.strip().split(';')
if int(l[2]) >= 0:
items += [l[1]]
itemss += [l[0]]
f.close()
p = 0
i = 0
j = 0
for idx in xrange(len(items)):
f = None
lines = sys.stdin.readlines()
for idx in xrange(len(lines)):
items = lines[idx].strip().split(';')
if idx % 8 == 0:
if not f.closed:
if f and not f.closed:
f.write(svgfoot)
f.close()
f = open('barcodes' + str(p) + '.svg','w')
@ -47,13 +36,11 @@ for idx in xrange(len(items)):
i = 0
j = 0
f.write(svghead)
elem = Popen(('zint','--directsvg','-d', itemss[idx]), stdout = PIPE).communicate()[0].split('\n')
elem = Popen(('zint','--directsvg','--notext', '-d', items[1]), stdout = PIPE).communicate()[0].split('\n')
elem = elem[8:-2]
elem[0] = elem[0].replace('id="barcode"', 'transform="matrix(%f,0,0,%f,%f,%f)"' % (scalex, scaley, 50+i*285 , 180+j*285) )
elem[21] = elem[21].replace(' y="59.00" ', ' y="69.00" ')
elem[22] = elem[22].replace(' font-size="8.0" ', ' font-size="14.0" ')
elem[23] = items[idx]
f.write('\n'.join(elem))
elem.insert(-1, ' <text x="39.50" y="69.00" text-anchor="middle" font-family="Helvetica" font-size="14.0" fill="#000000" >%s</text>' % items[0])
f.write('\n'.join(elem)+'\n\n')
i += 1
if i >= width:
i = 0

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
from flask import Flask, render_template
from flask import Flask, render_template, Response
from re import match
app = Flask('BrmBar')
@ -27,6 +27,18 @@ def code(code):
def admin():
return render_template('admin.html')
@app.route('/admin/barcode-generator.txt')
def admin_barcodegeneratortxt():
ret = []
ret.append('Credit 100;$100')
ret.append('Credit 200;$200')
ret.append('Credit 500;$500')
ret.append('Credit 1000;$1000')
ret.append('RESET;RST')
# TODO: add users in form <username>;U<userid>
response = Response(response = '\n'.join(ret) + '\n', content_type = 'text/plain')
return response
@app.route('/log/')
def log():
return render_template('log.html')

View file

@ -1,5 +1,7 @@
{% extends "base.html" %}
{% block title %}Admin{% endblock %}
{% block content %}
admin
<p><a href="barcode-generator.txt">barcode generator input</a></p>
{% endblock %}