Subversion Repositories navi

Rev

Rev 6 | Rev 8 | 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")
6 szabot 40
        for thing in db.query("""
7 szabot 41
        SELECT infixes, CHAR_LENGTH(navi) AS NL
6 szabot 42
        FROM `metaWords`
43
        ORDER BY NL DESC"""):
7 szabot 44
            text = "<br />".join((text, thing["infixes"]))
2 szabot 45
        self.write(text)
46
 
47
application = tornado.web.Application([
48
    ("/", Index),
49
    ("/number", Number),
50
    ("/restart", Restart),
51
    ("/testdb", TestDB)
52
])
53
 
54
if __name__ == "__main__":
55
    http_server = tornado.httpserver.HTTPServer(application)
56
    http_server.listen(1337)
57
    tornado.autoreload.start()
58
    tornado.ioloop.IOLoop.instance().start()