Subversion Repositories navi

Rev

Rev 150 | Rev 176 | 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):
152 szabot 63
        self.render("templates/translate.html", last="", out=None, lang="eng")
146 szabot 64
 
65
    def post(self):
66
        try:
67
            word = self.get_argument("word")
150 szabot 68
            lang = self.get_argument("lang")
146 szabot 69
        except:
70
            self.redirect("/translate")
150 szabot 71
        out = translate.translatesent(word, lang)
152 szabot 72
        self.render("templates/translate.html", last=word, out=out, lang=lang)
146 szabot 73
 
132 szabot 74
settings = {
75
    "static_path": os.path.join(os.path.dirname(__file__), "static")
76
}
77
 
2 szabot 78
application = tornado.web.Application([
79
    ("/", Index),
80
    ("/number", Number),
81
    ("/restart", Restart),
49 szabot 82
    ("/testdb", TestDB),
146 szabot 83
    ("/parse", Parse),
84
    ("/translate", Translate)
132 szabot 85
], **settings)
2 szabot 86
 
87
if __name__ == "__main__":
88
    http_server = tornado.httpserver.HTTPServer(application)
89
    http_server.listen(1337)
70 szabot 90
    #tornado.autoreload.start()
122 szabot 91
    tornado.ioloop.IOLoop.instance().start()