Subversion Repositories navi

Rev

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