Subversion Repositories navi

Rev

Rev 132 | Rev 152 | 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
 
9
import os
16 szabot 10
import re
2 szabot 11
 
49 szabot 12
from tsimapiak import parsenum
13
from tsimapiak import dbconnector
14
from tsimapiak import parse
146 szabot 15
from tsimapiak import translate
2 szabot 16
 
17
class Index(tornado.web.RequestHandler):
18
    def get(self):
122 szabot 19
        self.render("templates/index.html")
2 szabot 20
 
21
class Number(tornado.web.RequestHandler):
22
    def get(self):
23
        self.render("templates/number.html", last="", numout=None)
24
 
25
    def post(self):
26
        try:
27
            num = self.get_argument("num").strip()
28
        except:
29
            self.redirect("/number")
49 szabot 30
        numout = parsenum.parse(num.replace(" ",""))
2 szabot 31
        if numout == None:
103 szabot 32
            numoutt = -1
33
        else:
117 szabot 34
            numoutt = (numout["dec"], numout["oct"])
103 szabot 35
        self.render("templates/number.html", last=num, numout=numoutt)
2 szabot 36
 
37
class Restart(tornado.web.RequestHandler):
38
    def get(self):
39
        os.system("/usr/bin/restartnavi")
40
 
10 szabot 41
 
2 szabot 42
class TestDB(tornado.web.RequestHandler):
43
    def get(self):
49 szabot 44
        lis = dbconnector.getnavilist()
39 szabot 45
        text = u"id | navi | infix | partofspeech<br />"
46
        text += u"<br />".join(u" | ".join(unicode(y) for y in x) for x in lis)
2 szabot 47
        self.write(text)
48
 
56 szabot 49
class Parse(tornado.web.RequestHandler):
49 szabot 50
    def get(self):
50 szabot 51
        self.render("templates/parse.html", last="", out=None)
49 szabot 52
 
53
    def post(self):
54
        try:
117 szabot 55
            word = self.get_argument("word")
49 szabot 56
        except:
57
            self.redirect("/parse")
117 szabot 58
        out = parse.parsesent(word)
50 szabot 59
        self.render("templates/parse.html", last=word, out=out)
49 szabot 60
 
146 szabot 61
class Translate(tornado.web.RequestHandler):
62
    def get(self):
63
        self.render("templates/translate.html", last="", out=None)
64
 
65
    def post(self):
66
        try:
67
            word = self.get_argument("word")
68
        except:
69
            self.redirect("/translate")
70
        out = translate.translatesent(word)
71
        self.render("templates/translate.html", last=word, out=out)
72
 
132 szabot 73
settings = {
74
    "static_path": os.path.join(os.path.dirname(__file__), "static")
75
}
76
 
2 szabot 77
application = tornado.web.Application([
78
    ("/", Index),
79
    ("/number", Number),
80
    ("/restart", Restart),
49 szabot 81
    ("/testdb", TestDB),
146 szabot 82
    ("/parse", Parse),
83
    ("/translate", Translate)
132 szabot 84
], **settings)
2 szabot 85
 
86
if __name__ == "__main__":
87
    http_server = tornado.httpserver.HTTPServer(application)
88
    http_server.listen(1337)
70 szabot 89
    #tornado.autoreload.start()
122 szabot 90
    tornado.ioloop.IOLoop.instance().start()