drime

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

commit 4a585843c14b255bc1f16dd80b08964b3fd231d5
parent cce9d0f47200f4b81b5dc1a8985b51945f3a6d83
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Sat, 24 Dec 2011 01:04:46 +0100

improve rendering, switch to mysql

Diffstat:
db_mysql.py | 18++++++++++++++++++
db_sqlite.py | 15+++++++++++++++
query.py | 12++----------
static/main.css | 4++++
templates/about.html | 3++-
templates/disambig.html | 15++++++++++++---
templates/results.html | 2+-
7 files changed, 54 insertions(+), 15 deletions(-)

diff --git a/db_mysql.py b/db_mysql.py @@ -0,0 +1,18 @@ +#!/usr/bin/python3 -O + +import MySQLdb +import MySQLdb.cursors +from db_mysql_config import config + +def run_query(r, v): + db = MySQLdb.connect( + host=config.host, + user=config.user, + passwd=config.passwd, + db=config.db, + cursorclass=MySQLdb.cursors.DictCursor, + use_unicode=True) + cursor = db.cursor() + cursor.execute(r.replace('?', '%s'), v) + return cursor + diff --git a/db_sqlite.py b/db_sqlite.py @@ -0,0 +1,15 @@ +#!/usr/bin/python3 -O + +import sqlite3 +import os + +DBPATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), + 'db.sqlite') + +def run_query(r, v): + db = sqlite3.connect(DBPATH) + db.row_factory = sqlite3.Row + cursor = db.cursor() + cursor.execute(r, v) + return cursor + diff --git a/query.py b/query.py @@ -1,14 +1,10 @@ #!/usr/bin/python3 -O -import sqlite3 -import os import sys import operator +from db_mysql import run_query PAGESIZE=50 -DBPATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), - 'db.sqlite') - def lcs(x, y): """Longest common suffix""" @@ -60,10 +56,7 @@ pass def do_query(word, phon, minsyll, maxsyll, elide, gender, offset, size): print ((word, phon, minsyll, maxsyll, elide, gender,)) - db = sqlite3.connect(DBPATH) - db.row_factory = sqlite3.Row - cursor = db.cursor() - cursor.execute(''' + cursor = run_query(''' SELECT t1.freq AS t1_freq, t1.word AS t1_word, t1.phon AS t1_phon, @@ -87,7 +80,6 @@ def do_query(word, phon, minsyll, maxsyll, elide, gender, offset, size): minsyll == None, minsyll, maxsyll == None, maxsyll, maxsyll,)) result = {} cache = {} - ncache = {} seen = {} for x in cursor: if x['t1_feminine'] != x['t2_feminine'] and gender: diff --git a/static/main.css b/static/main.css @@ -45,3 +45,7 @@ label { table { width: 100%; } + +.odd { + background: #efe; +} diff --git a/templates/about.html b/templates/about.html @@ -2,7 +2,8 @@ {% block body %} TODO move this to / -<h2 id="info">What is this?</h2> +<p>Welcome to <strong>drime</strong>!</p> +<h2 id="info">Wait, what is this?</h2> <p>This is drime, <a href="http://a3nm.net">a3nm</a>'s attempt to build a better French rhyme dictionary. It uses the <a href="http://www.lexique.org/">Lexique</a> database with some customisations, diff --git a/templates/disambig.html b/templates/disambig.html @@ -4,11 +4,20 @@ <p>Did you mean:</p> TODO include indications TODO keep the other GET params -<ul> +<table> {% for k in keys %} -<li><a href="?query={{ k[-1] }}">{{ k[-1] }}</a></li> +<a href="?query={{ k[-1] | escape }}&nsyl={{ nsyl }}&gender={{ gender }}"> + <tr class="{% loop.cycle('odd', 'even') %}"> + <td>{{ k[0] }}</td> + <td>{{ k[1] }}</td> + <td> + {% for v in result[k][:5] %} + {{ v[0] }} + {% endfor %} + </td> + </tr> {% endfor %} -</ul> +</table> {% endblock %} diff --git a/templates/results.html b/templates/results.html @@ -10,7 +10,7 @@ <th>derivation</th> <th>freq</th> {% for r in result %} -<tr> +<tr class="{{ loop.cycle('odd', 'even') }}"> <td>{{ r.word }}</td> <td>{{ r.phon }}</td> <td class="num">{{ r.phon_rhyme }}</td>