drime

French rhyme dictionary with web and CLI interface
git clone https://a3nm.net/git/drime/
Log | Files | Refs | README

commit 70dbc1722aa4cdd71da3c60cc94be49b2ee43a11
parent 35ca9975ad4c151a40ce90ac9ba47c9737b4b127
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Tue, 27 Dec 2011 01:17:57 +0100

missing file

Diffstat:
server.py | 49+++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+), 0 deletions(-)

diff --git a/server.py b/server.py @@ -0,0 +1,49 @@ +import query +from flask import Flask, render_template, request + +app = Flask(__name__) + +@app.route('/') +def root(): + return render_template('about.html', title="drime") + +@app.route('/query') +def q(): + d = { + 'q': request.args.get('query'), + 'nsyl': request.args.get('nsyl'), + 'gender': request.args.get('gender'), + 'page': request.args.get('page'), + } + if not d['page']: + d['page'] = 0 + try: + d['page'] = int(d['page']) + except ValueError: + d['page'] = 0 + try: + r, count = query.query(**d) + d['pagesize'] = query.PAGESIZE + d['mode'] = 'query' + d['title'] = 'drime' + d['count'] = count + d['displayed'] = min(d['pagesize'], count) + d['keys'] = sorted(r.keys()) + if len(r.keys()) == 0: + return render_template('notfound.html', **d) + elif len(r.keys()) > 1: + #d['example'] = {} + #for k in d['keys']: + #d['example'][k] = r[k] + return render_template('disambig.html', **d) + else: + d['result'] = r[r.keys()[0]] + return render_template('results.html', **d) + except query.BadValues: + d['mode'] = 'query' + return render_template('error.html', **d) + +if __name__ == '__main__': + app.debug = True + app.run() +