drime

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

commit 6ce5cb23a65b5ae19f10a2f4bd6f2dc24f612bb6
parent c5152af4d38e93f951c36ef8e04c3d2b272188a7
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Tue, 27 Dec 2011 01:33:09 +0100

create drime.wsgi and rename server.py

Diffstat:
drime.py | 48++++++++++++++++++++++++++++++++++++++++++++++++
drime.wsgi | 1+
server.py | 48------------------------------------------------
3 files changed, 49 insertions(+), 48 deletions(-)

diff --git a/drime.py b/drime.py @@ -0,0 +1,48 @@ +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.run() + diff --git a/drime.wsgi b/drime.wsgi @@ -0,0 +1 @@ +from drime import app as application diff --git a/server.py b/server.py @@ -1,48 +0,0 @@ -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.run() -