Subversion Repositories navi

Rev

Rev 25 | Rev 27 | 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"  "," ") \
46
           .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""
2 szabot 55
        db = tornado.database.Connection("127.0.0.1", "navi", user="navi", password="navi")
6 szabot 56
        for thing in db.query("""
10 szabot 57
        SELECT *, CHAR_LENGTH(navi) AS NL
6 szabot 58
        FROM `metaWords`
17 szabot 59
        WHERE partOfSpeech IN ('v.', 'vin.', 'vtr,')
60
        ORDER BY NL DESC"""):
26 szabot 61
            text += unicode(thing["navi"]) + u" - " + clear(unicode(thing["ipa"])) + u"     -     " + unicode(unicode(thing["navi"]) == clear(unicode(thing["ipa"])).replace(ur"$cdot$",ur"")) + u"<br />"
2 szabot 62
        self.write(text)
63
 
64
application = tornado.web.Application([
65
    ("/", Index),
66
    ("/number", Number),
67
    ("/restart", Restart),
68
    ("/testdb", TestDB)
69
])
70
 
71
if __name__ == "__main__":
72
    http_server = tornado.httpserver.HTTPServer(application)
73
    http_server.listen(1337)
74
    tornado.autoreload.start()
75
    tornado.ioloop.IOLoop.instance().start()