[Assorted-commits] SF.net SVN: assorted:[1039] sandbox/trunk/src/one-off-scripts
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-10-26 23:50:17
|
Revision: 1039 http://assorted.svn.sourceforge.net/assorted/?rev=1039&view=rev Author: yangzhang Date: 2008-10-26 23:50:08 +0000 (Sun, 26 Oct 2008) Log Message: ----------- added pronunciation trainer Added Paths: ----------- sandbox/trunk/src/one-off-scripts/pronunciation-trainer/ sandbox/trunk/src/one-off-scripts/pronunciation-trainer/test.cgi Added: sandbox/trunk/src/one-off-scripts/pronunciation-trainer/test.cgi =================================================================== --- sandbox/trunk/src/one-off-scripts/pronunciation-trainer/test.cgi (rev 0) +++ sandbox/trunk/src/one-off-scripts/pronunciation-trainer/test.cgi 2008-10-26 23:50:08 UTC (rev 1039) @@ -0,0 +1,63 @@ +#!/usr/bin/env /mit/y_z/.local/armed/bin/mit-mako-render +Content-type: text/html; charset=UTF-8 +<% +import cgitb +cgitb.enable() +import cgi, codecs, re +from cPickle import load, dump +from commons.strs import unicode2html as uh, quotejs as js, html2unicode + +form = cgi.FieldStorage() + +if 'src' in form: + try: + f = file('cedict.pickle', 'rb') + try: simp2info = load(f) + finally: f.close() + except: + f = codecs.open('cedict.txt', 'r', 'utf-8') + try: + simp2info = {} + for line in f: + m = re.match( ur'(?P<simp>[^ ]+) ' + ur'(?P<trad>[^ ]+) ' + ur'\[(?P<pinyin>[^\]]+)\] ' + ur'\/(?P<english>.+)\/( *#.*)?', line ) + if m: + simp, trad, pinyin, english = \ + map( m.group, 'simp trad pinyin english'.split() ) + simp2info[simp] = (pinyin, english) + dump( simp2info, file('cedict.pickle', 'wb'), 2 ) + finally: + f.close() + + src = form['src'].value.decode('utf-8') # html2unicode(form['src'].value) + dst = u''.join( simp2info.get(c, u'__')[0] for c in src ) +else: + src = u'' + dst = u'' +%> + +<html> + ##<script> + ## var p = new Array(); + ## var e = new Array(); + ## % for simp, (pinyin, english) in simp2info.items(): + ## p['${simp|js}'] = '${pinyin|js}' + ## e['${simp|js}'] = '${english|js}' + ## % endfor + ##</script> + ##% for simp, (pinyin, english) in simp2info.items()[:1]: + ## <p> + ## simplified: ${simp|uh}<br/> + ## pinyin: ${pinyin|uh}<br/> + ## english: ${english|uh}<br/> + ## </p> + ##% endfor + <form method="post" enctype="multipart/form-data"> + <p><textarea name="src">${src|uh}</textarea></p> + <p><textarea name="dst">${dst|uh}</textarea></p> + <p><input name="submit" type="submit"/></p> + </form> +</html> +## vim:ft=mako This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |