rework server to use flask, new items

This commit is contained in:
Pavol Rusnak 2011-06-12 23:10:22 +02:00
parent 99893f58a0
commit bd828a71e8
8 changed files with 84 additions and 35 deletions

View file

@ -9,8 +9,12 @@ RST;RESET credit;30000
4029764001807;Club Mate 0.5L;-35
4029764001821;Club Mate 0.33L;-25
5018374350930;Tesco Baked Beans in Tomato Sauce;-20
7622300331436;Delissa mlecna;-10
7622300331498;Delissa oriskova;-10
7622300331436;Siesta mlecna;-10
7622300331467;Siesta horka;-10
7622300331498;Siesta oriskova;-10
7613031880065;Delissa oriskova;-7
7613031880003;Delissa vanilkova;-7
7613031879946;Delissa cokoladova;-7
8593868000555;Pivo Branik 10% svetle;-25
8594404000329;Pivo Gambrinus 10% svetle;-25
8594404001241;Pivo Radegast 10% svetle;-25
@ -21,3 +25,26 @@ RST;RESET credit;30000
8594033171902;Big Shock tycinka;-15
85909311;Margot tycinka;-15
8584004041198;Tatranky;-8
85917095;Margot tycinka +20%;-17
8593894800075;Bebe cokoladove;-15
5906747308803;Pim's coko piskoty visnove;-30
8584004010200;Kavenky;-10
8586011330463;Vinea Biela;-50
8586011330470;Vinea Cervena;-50
8593894911030;Zlate oplatky liskooriskove;-17
8593894911122;Zlate oplatky smetanove;-17
85951631;Frisco brusinka;-25
8593868110445;Staropramen 10%;-25
8714800011426;Bavaria 0.0%;-25
8594003844782;Orangina zluta;-25
3155930006015;Desperados 0.33l;-40
5060166692636;Monster Ripper 0.5l;-35
8585002408976;Kure na paprice;-35
8593837223220;Kure na paprice;-35
8593837223213;Gulas;-35
8593837223176;Bolonska omacka;-35
031146254903;Big Ramen - Shin Cup Noodle Soup;-35
031146254019;Big Ramen - Noodle Shrimp Flavour;-35
85933323;Deli pistaciova;-10
85933354;Deli cokoladova;-10
8594067540071;Prave hospodske bramburky;-12

View file

@ -1,41 +1,28 @@
#!/usr/bin/env python
#!/usr/bin/python
import BaseHTTPServer
from flask import Flask, render_template
class BrmbarHandler(BaseHTTPServer.BaseHTTPRequestHandler):
app = Flask('BrmBar')
def do_GET(self):
action = self.path.split('/')[1:]
@app.route('/')
def index():
return render_template('index.html')
if action[0] == 'code':
self.code(action[1])
return
@app.route('/code/<code>')
def code(code):
return 'CODE "%s" received' % code
if action[0] == 'favicon.ico':
self.send_file('favicon.png', 'image/png')
return
@app.route('/admin/')
def admin():
return render_template('admin.html')
self.send_response(404)
@app.route('/log/')
def log():
return render_template('log.html')
def code(self, code):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write('CODE "%s" received\n' % code)
@app.route('/stats/')
def stats():
return render_template('stats.html')
def send_file(self, filename, mimetype):
self.send_response(200)
self.send_header('Content-type', mimetype)
self.end_headers()
f = open(filename, 'r')
self.wfile.write(f.read())
f.close()
try:
server_address = ('', 8000)
httpd = BaseHTTPServer.HTTPServer(server_address, BrmbarHandler)
print 'Starting BrmBar server ...'
httpd.serve_forever()
except KeyboardInterrupt:
print 'Shutting down ...'
httpd.socket.close()
if __name__ == '__main__':
app.run()

View file

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Before After
Before After

View file

@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block title %}Admin{% endblock %}
{% block content %}
admin
{% endblock %}

View file

@ -0,0 +1,15 @@
<html>
<head>
<title>BrmBar: {% block title %}{% endblock %}</title>
<link rel="icon" type="image/png" href="/static/favicon.png">
</head>
<body>
<h1><img src="/static/favicon.png" valign="middle" /> BrmBar: {{ self.title() }}</h1>
<div id="menu">
<a href="/">home</a> | <a href="/stats/">stats</a> | <a href="/log/">log</a> | <a href="/admin/">admin</a>
</div>
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
</html>

View file

@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block title %}Welcome{% endblock %}
{% block content %}
welcome
{% endblock %}

View file

@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block title %}Log{% endblock %}
{% block content %}
log
{% endblock %}

View file

@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block title %}Stats{% endblock %}
{% block content %}
stats
{% endblock %}