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