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