Subversion Repositories navi

Rev

Rev 208 | Rev 240 | 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)
239 muzer 85
class Errors(tornado.web.RequestHandler):
86
    def get_error_html(self, status_code, **kwargs):
87
        if status_code == 500:
88
        return "<html><title>%(code)d: %(message)s</title>" \
89
            "<body>%(code)d: %(message)s<br /><br />Either we are currently working on the server, or you uncovered a bug. Please check back later on. If you still get this error, please report this bug to us in the forum thread or on IRC.</body></html>" % {
90
            "code": status_code,
91
            "message": httplib.responses[status_code],
92
            }
93
        else:
94
        return "<html><title>%(code)d: %(message)s</title>" \
95
            "<body>%(code)d: %(message)s</body></html>" % {
96
            "code": status_code,
97
            "message": httplib.responses[status_code],
98
            }
146 szabot 99
 
132 szabot 100
settings = {
101
    "static_path": os.path.join(os.path.dirname(__file__), "static")
102
}
103
 
2 szabot 104
application = tornado.web.Application([
105
    ("/", Index),
106
    ("/number", Number),
107
    ("/restart", Restart),
146 szabot 108
    ("/parse", Parse),
109
    ("/translate", Translate)
132 szabot 110
], **settings)
2 szabot 111
 
112
if __name__ == "__main__":
113
    http_server = tornado.httpserver.HTTPServer(application)
114
    http_server.listen(1337)
70 szabot 115
    #tornado.autoreload.start()
176 muzer 116
    tornado.ioloop.IOLoop.instance().start()