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