Subversion Repositories navi

Rev

Rev 28 | Rev 30 | 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
16 szabot 11
import re
2 szabot 12
 
4 szabot 13
from tsimapiak.parsenum import parse
2 szabot 14
 
15
class Index(tornado.web.RequestHandler):
16
    def get(self):
17
        self.redirect("/number")
18
 
19
class Number(tornado.web.RequestHandler):
20
    def get(self):
21
        self.render("templates/number.html", last="", numout=None)
22
 
23
    def post(self):
24
        try:
25
            num = self.get_argument("num").strip()
26
        except:
27
            self.redirect("/number")
28
        numout = parse(num.replace(" ",""))
29
        if numout == None:
30
            numout = -1
31
        self.render("templates/number.html", last=num, numout=numout)
32
 
33
class Restart(tornado.web.RequestHandler):
34
    def get(self):
35
        os.system("/usr/bin/restartnavi")
36
 
10 szabot 37
def clear(s):
16 szabot 38
    s = s.replace(ur"ɛ",ur"e").replace(ur".",ur"").replace(ur"ɾ",ur"r") \
14 szabot 39
           .replace(ur"ɪ",ur"ì").replace(ur"ˈ",ur"").replace(ur"'",ur"x") \
40
           .replace(ur"ŋ",ur"ng").replace(ur"j",ur"y").replace(ur"ʔ",ur"'") \
41
           .replace(ur"æ",ur"ä").replace(ur"ˌ",ur"").replace(ur"\t{ts}",ur"ts") \
16 szabot 42
           .replace(ur"ṛ",ur"rr").replace(ur"ḷ",ur"ll").replace(ur"k̚",ur"k ") \
43
           .replace(ur"p̚",ur"p ").replace(ur"t̚",ur"t ").replace(ur"'̚",ur"' ") \
44
           .replace(u"\\",ur"").replace(ur"(",ur"").replace(ur")",ur"") \
26 szabot 45
           .replace(ur"[",ur"").replace(ur"]",ur"").replace(ur"  "," ") \
27 szabot 46
           .replace(ur"$cdot$",ur"[^ ]").strip()
16 szabot 47
    s = re.sub(ur" or.*","",s)
24 szabot 48
    s = re.sub(ur"z(.*)engk(.*)e",ur"z\1enk\2e",s)
25 szabot 49
    s = re.sub(ur"t(.*)ì(m|n)\ ",ur"t\1ìng ",s)
16 szabot 50
    return s
10 szabot 51
 
2 szabot 52
class TestDB(tornado.web.RequestHandler):
53
    def get(self):
9 szabot 54
        text = u""
27 szabot 55
        current = u""
2 szabot 56
        db = tornado.database.Connection("127.0.0.1", "navi", user="navi", password="navi")
6 szabot 57
        for thing in db.query("""
27 szabot 58
        SELECT *, CHAR_LENGTH(navi) AS NL
59
        FROM `metaWords`
17 szabot 60
        ORDER BY NL DESC"""):
27 szabot 61
            if thing["partOfSpeech"] in (u"v.", u"vin.", u"vtr."):
62
                current = clear(unicode(thing["ipa"]))
63
            else:
64
                current = unicode(thing["navi"])
29 szabot 65
            current = u" ".join([ur"[^ ]*"+x+ur"[^ ]*" for x in re.split(ur" (?=[^\]])",current)])
27 szabot 66
            text += current + u"<br />"
2 szabot 67
        self.write(text)
68
 
69
application = tornado.web.Application([
70
    ("/", Index),
71
    ("/number", Number),
72
    ("/restart", Restart),
73
    ("/testdb", TestDB)
74
])
75
 
76
if __name__ == "__main__":
77
    http_server = tornado.httpserver.HTTPServer(application)
78
    http_server.listen(1337)
79
    tornado.autoreload.start()
80
    tornado.ioloop.IOLoop.instance().start()