Subversion Repositories navi

Rev

Rev 49 | Rev 56 | 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
2 szabot 15
 
16
class Index(tornado.web.RequestHandler):
17
    def get(self):
18
        self.redirect("/number")
19
 
20
class Number(tornado.web.RequestHandler):
21
    def get(self):
22
        self.render("templates/number.html", last="", numout=None)
23
 
24
    def post(self):
25
        try:
26
            num = self.get_argument("num").strip()
27
        except:
28
            self.redirect("/number")
49 szabot 29
        numout = parsenum.parse(num.replace(" ",""))
2 szabot 30
        if numout == None:
31
            numout = -1
32
        self.render("templates/number.html", last=num, numout=numout)
33
 
34
class Restart(tornado.web.RequestHandler):
35
    def get(self):
36
        os.system("/usr/bin/restartnavi")
37
 
10 szabot 38
 
2 szabot 39
class TestDB(tornado.web.RequestHandler):
40
    def get(self):
49 szabot 41
        lis = dbconnector.getnavilist()
39 szabot 42
        text = u"id | navi | infix | partofspeech<br />"
43
        text += u"<br />".join(u" | ".join(unicode(y) for y in x) for x in lis)
2 szabot 44
        self.write(text)
45
 
49 szabot 46
class ParseTest(tornado.web.RequestHandler):
47
    def get(self):
50 szabot 48
        self.render("templates/parse.html", last="", out=None)
49 szabot 49
 
50
    def post(self):
51
        try:
52
            word = self.get_argument("word").strip()
53
        except:
54
            self.redirect("/parse")
55
        out = parse.parsefix(word)
50 szabot 56
        self.render("templates/parse.html", last=word, out=out)
49 szabot 57
 
2 szabot 58
application = tornado.web.Application([
59
    ("/", Index),
60
    ("/number", Number),
61
    ("/restart", Restart),
49 szabot 62
    ("/testdb", TestDB),
63
    ("/parse", ParseTest)
2 szabot 64
])
65
 
66
if __name__ == "__main__":
67
    http_server = tornado.httpserver.HTTPServer(application)
68
    http_server.listen(1337)
69
    tornado.autoreload.start()
70
    tornado.ioloop.IOLoop.instance().start()