Subversion Repositories navi

Rev

Rev 176 | Rev 208 | 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 -*-
176 muzer 3
#    This file is part of Tsim Apiak.
4
#
5
#    Tsim Apiak is free software: you can redistribute it and/or modify
6
#    it under the terms of the GNU General Public Licence as published by
7
#    the Free Software Foundation, either version 3 of the Licence, or
8
#    (at your option) any later version. 
9
# 
10
#    In addition to this, you must also comply with clause 4 of the
11
#    Apache Licence, version 2.0, concerning attribution. Where there
12
#    is a contradiction between the two licences, the GPL           
13
#    takes preference.
14
#
186 szabot 15
#    Tsim Apiak is distributed in the hope that it will be useful,
176 muzer 16
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
#    GNU General Public License for more details.
19
#
20
#    You should have received a copy of the GNU General Public License
21
#    along with Tsim Apiak.  If not, see <http://www.gnu.org/licenses/>.
2 szabot 22
 
176 muzer 23
 
2 szabot 24
import tornado.httpserver
25
import tornado.ioloop
26
import tornado.web
27
import tornado.autoreload
28
 
29
import os
16 szabot 30
import re
2 szabot 31
 
49 szabot 32
from tsimapiak import parsenum
33
from tsimapiak import dbconnector
34
from tsimapiak import parse
146 szabot 35
from tsimapiak import translate
2 szabot 36
 
37
class Index(tornado.web.RequestHandler):
38
    def get(self):
122 szabot 39
        self.render("templates/index.html")
2 szabot 40
 
41
class Number(tornado.web.RequestHandler):
42
    def get(self):
43
        self.render("templates/number.html", last="", numout=None)
44
 
45
    def post(self):
46
        try:
47
            num = self.get_argument("num").strip()
48
        except:
49
            self.redirect("/number")
49 szabot 50
        numout = parsenum.parse(num.replace(" ",""))
2 szabot 51
        if numout == None:
103 szabot 52
            numoutt = -1
53
        else:
117 szabot 54
            numoutt = (numout["dec"], numout["oct"])
103 szabot 55
        self.render("templates/number.html", last=num, numout=numoutt)
2 szabot 56
 
57
class Restart(tornado.web.RequestHandler):
58
    def get(self):
59
        os.system("/usr/bin/restartnavi")
60
 
10 szabot 61
 
2 szabot 62
class TestDB(tornado.web.RequestHandler):
63
    def get(self):
49 szabot 64
        lis = dbconnector.getnavilist()
39 szabot 65
        text = u"id | navi | infix | partofspeech<br />"
66
        text += u"<br />".join(u" | ".join(unicode(y) for y in x) for x in lis)
2 szabot 67
        self.write(text)
68
 
56 szabot 69
class Parse(tornado.web.RequestHandler):
49 szabot 70
    def get(self):
50 szabot 71
        self.render("templates/parse.html", last="", out=None)
49 szabot 72
 
73
    def post(self):
74
        try:
117 szabot 75
            word = self.get_argument("word")
49 szabot 76
        except:
77
            self.redirect("/parse")
117 szabot 78
        out = parse.parsesent(word)
50 szabot 79
        self.render("templates/parse.html", last=word, out=out)
49 szabot 80
 
146 szabot 81
class Translate(tornado.web.RequestHandler):
82
    def get(self):
152 szabot 83
        self.render("templates/translate.html", last="", out=None, lang="eng")
146 szabot 84
 
85
    def post(self):
86
        try:
87
            word = self.get_argument("word")
150 szabot 88
            lang = self.get_argument("lang")
146 szabot 89
        except:
90
            self.redirect("/translate")
150 szabot 91
        out = translate.translatesent(word, lang)
152 szabot 92
        self.render("templates/translate.html", last=word, out=out, lang=lang)
146 szabot 93
 
132 szabot 94
settings = {
95
    "static_path": os.path.join(os.path.dirname(__file__), "static")
96
}
97
 
2 szabot 98
application = tornado.web.Application([
99
    ("/", Index),
100
    ("/number", Number),
101
    ("/restart", Restart),
49 szabot 102
    ("/testdb", TestDB),
146 szabot 103
    ("/parse", Parse),
104
    ("/translate", Translate)
132 szabot 105
], **settings)
2 szabot 106
 
107
if __name__ == "__main__":
108
    http_server = tornado.httpserver.HTTPServer(application)
109
    http_server.listen(1337)
70 szabot 110
    #tornado.autoreload.start()
176 muzer 111
    tornado.ioloop.IOLoop.instance().start()