Subversion Repositories navi

Rev

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