#!/usr/bin/env python # -*- encoding: utf-8 -*- ''' @File : app.py @Author: liuyihui @Email : liuyihui02@gmail.com ''' # here put the import lib import os import lib.elo as elo import lib.utils as utils from flask import Flask, request, redirect, render_template P0 = None P1 = None ses = utils.get_session() app = Flask(__name__, template_folder='./templates/', static_folder='./static/') app.config['ROOT_FOLDER'] = os.path.abspath('.') @app.route('/', methods=["GET"]) @app.route('/new', methods=["GET"]) def root(): global P0, P1 P0, P1 = utils.match(ses) return render_template( 'index.html', p0src='./static/pic/{:d}.jpeg'.format(P0.id), p0name=P0.name, p0work='{:.2f}'.format(P0.rate), p1src='./static/pic/{:d}.jpeg'.format(P1.id), p1name=P1.name, p1work='{:.2f}'.format(P1.rate) ) @app.route('/elo', methods=["GET"]) def elo_res(): res = request.args.get('win') elo.set_result(P0, P1, int(res)) ses.commit() return redirect('/new') if __name__ == '__main__': app.run(debug=True, host='0.0.0.0', port=4002)