Rev 103 | Rev 122 | 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: |
103 | szabot | 31 | numoutt = -1 |
32 | else: |
||
117 | szabot | 33 | numoutt = (numout["dec"], numout["oct"]) |
103 | szabot | 34 | self.render("templates/number.html", last=num, numout=numoutt) |
2 | szabot | 35 | |
36 | class Restart(tornado.web.RequestHandler): |
||
37 | def get(self): |
||
38 | os.system("/usr/bin/restartnavi") |
||
39 | |||
10 | szabot | 40 | |
2 | szabot | 41 | class TestDB(tornado.web.RequestHandler): |
42 | def get(self): |
||
49 | szabot | 43 | lis = dbconnector.getnavilist() |
39 | szabot | 44 | text = u"id | navi | infix | partofspeech<br />" |
45 | text += u"<br />".join(u" | ".join(unicode(y) for y in x) for x in lis) |
||
2 | szabot | 46 | self.write(text) |
47 | |||
56 | szabot | 48 | class Parse(tornado.web.RequestHandler): |
49 | szabot | 49 | def get(self): |
50 | szabot | 50 | self.render("templates/parse.html", last="", out=None) |
49 | szabot | 51 | |
52 | def post(self): |
||
53 | try: |
||
117 | szabot | 54 | word = self.get_argument("word") |
49 | szabot | 55 | except: |
56 | self.redirect("/parse") |
||
117 | szabot | 57 | out = parse.parsesent(word) |
50 | szabot | 58 | self.render("templates/parse.html", last=word, out=out) |
49 | szabot | 59 | |
2 | szabot | 60 | application = tornado.web.Application([ |
61 | ("/", Index), |
||
62 | ("/number", Number), |
||
63 | ("/restart", Restart), |
||
49 | szabot | 64 | ("/testdb", TestDB), |
117 | szabot | 65 | ("/parse", Parse) |
2 | szabot | 66 | ]) |
67 | |||
68 | if __name__ == "__main__": |
||
69 | http_server = tornado.httpserver.HTTPServer(application) |
||
70 | http_server.listen(1337) |
||
70 | szabot | 71 | #tornado.autoreload.start() |
2 | szabot | 72 | tornado.ioloop.IOLoop.instance().start() |