Subversion Repositories navi

Rev

Rev 12 | Rev 14 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 szabot 1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
 
4
import tornado.httpserver
5
import tornado.ioloop
6
import tornado.web
7
import tornado.autoreload
8
import tornado.database
9
 
10
import os
11
 
4 szabot 12
from tsimapiak.parsenum import parse
2 szabot 13
 
14
class Index(tornado.web.RequestHandler):
15
    def get(self):
16
        self.redirect("/number")
17
 
18
class Number(tornado.web.RequestHandler):
19
    def get(self):
20
        self.render("templates/number.html", last="", numout=None)
21
 
22
    def post(self):
23
        try:
24
            num = self.get_argument("num").strip()
25
        except:
26
            self.redirect("/number")
27
        numout = parse(num.replace(" ",""))
28
        if numout == None:
29
            numout = -1
30
        self.render("templates/number.html", last=num, numout=numout)
31
 
32
class Restart(tornado.web.RequestHandler):
33
    def get(self):
34
        os.system("/usr/bin/restartnavi")
35
 
10 szabot 36
def clear(s):
12 szabot 37
    return s.replace(u"ɛ",u"e").replace(u".",u"").replace(u"ɾ",u"r") \
38
           .replace(u"ɪ",u"ì").replace(u"ˈ",u"").replace(u"'",u"x") \
39
           .replace(u"ŋ",u"ng").replace(u"j",u"y").replace(u"ʔ",u"'") \
40
           .replace(u"æ",u"ä").replace(u"ˌ",u"").replace(u"\t{ts}",u"ts") \
41
           .replace(ur"$\cdot$",u"")
10 szabot 42
 
2 szabot 43
class TestDB(tornado.web.RequestHandler):
44
    def get(self):
9 szabot 45
        text = u""
2 szabot 46
        db = tornado.database.Connection("127.0.0.1", "navi", user="navi", password="navi")
6 szabot 47
        for thing in db.query("""
10 szabot 48
        SELECT *, CHAR_LENGTH(navi) AS NL
6 szabot 49
        FROM `metaWords`
50
        ORDER BY NL DESC"""):
13 szabot 51
            text += unicode(thing["navi"]) + u" - " + clear(unicode(thing["ipa"])) + unicode(thing.navi == clear(unicode(thing["ipa"]))) + u"<br />"
2 szabot 52
        self.write(text)
53
 
54
application = tornado.web.Application([
55
    ("/", Index),
56
    ("/number", Number),
57
    ("/restart", Restart),
58
    ("/testdb", TestDB)
59
])
60
 
61
if __name__ == "__main__":
62
    http_server = tornado.httpserver.HTTPServer(application)
63
    http_server.listen(1337)
64
    tornado.autoreload.start()
65
    tornado.ioloop.IOLoop.instance().start()