mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-07 21:04:00 +02:00
56 lines
1.4 KiB
Python
Executable file
56 lines
1.4 KiB
Python
Executable file
#!/usr/bin/python
|
|
|
|
from flask import Flask, render_template, Response
|
|
from re import match
|
|
from users import users
|
|
|
|
app = Flask('BrmBar')
|
|
|
|
@app.route('/')
|
|
def index():
|
|
return render_template('index.html')
|
|
|
|
@app.route('/code/<code>')
|
|
def code(code):
|
|
if code == 'RST':
|
|
return 'RESET received'
|
|
if match('^\$[0-9]+$', code):
|
|
amount = int(code[1:])
|
|
return 'CREDIT %d received' % amount
|
|
if match('^U[0-9]{4}$', code):
|
|
userid = int(code[1:])
|
|
return 'USER %s received' % userid
|
|
if match('^[0-9]+$', code):
|
|
return 'ITEM %s received' % code
|
|
abort(400)
|
|
|
|
@app.route('/admin/')
|
|
def admin():
|
|
return render_template('admin.html')
|
|
|
|
@app.route('/admin/barcode-generator.txt')
|
|
def admin_barcodegeneratortxt():
|
|
ret = []
|
|
ret.append('Credit 20;$20')
|
|
ret.append('Credit 50;$50')
|
|
ret.append('Credit 100;$100')
|
|
ret.append('Credit 200;$200')
|
|
ret.append('Credit 500;$500')
|
|
ret.append('Credit 1000;$1000')
|
|
ret.append('Credit 2000;$2000')
|
|
ret.append('RESET;RST')
|
|
for (id,name) in sorted(users.iteritems(), key = lambda (k,v): (v,k)):
|
|
ret.append('%s;U%d' % (name, id))
|
|
response = Response(response = '\n'.join(ret) + '\n', content_type = 'text/plain')
|
|
return response
|
|
|
|
@app.route('/log/')
|
|
def log():
|
|
return render_template('log.html')
|
|
|
|
@app.route('/stats/')
|
|
def stats():
|
|
return render_template('stats.html')
|
|
|
|
if __name__ == '__main__':
|
|
app.run(port = 45678)
|