Rev 9 | Rev 11 | 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 | |||
10 | szabot | 36 | def clear(s): |
37 | return s.replace("ɛ","e").replace(".","").replace("ɾ","r") \ |
||
38 | .replace("ɪ","ì").replace("ˈ","").replace("'","x") \ |
||
39 | .replace("ŋ","ng").replace("j","y").replace("ʔ","'") \ |
||
40 | .replace("æ","ä").replace("ˌ","").replace("\t{ts}","ts") \ |
||
41 | .replace(r"$\cdot$","") |
||
42 | |||
2 | szabot | 43 | class TestDB(tornado.web.RequestHandler): |
44 | def get(self): |
||
9 | szabot | 45 | text = u"" |
2 | szabot | 46 | db = tornado.database.Connection("127.0.0.1", "navi", user="navi", password="navi") |
6 | szabot | 47 | for thing in db.query(""" |
10 | szabot | 48 | SELECT *, CHAR_LENGTH(navi) AS NL |
6 | szabot | 49 | FROM `metaWords` |
50 | ORDER BY NL DESC"""): |
||
10 | szabot | 51 | text += thing.navi + " - " + clear(thing.ipa) + str(thing.navi == clear(thing.ipa)) + "<br />" |
2 | szabot | 52 | self.write(text) |
53 | |||
54 | application = tornado.web.Application([ |
||
55 | ("/", Index), |
||
56 | ("/number", Number), |
||
57 | ("/restart", Restart), |
||
58 | ("/testdb", TestDB) |
||
59 | ]) |
||
60 | |||
61 | if __name__ == "__main__": |
||
62 | http_server = tornado.httpserver.HTTPServer(application) |
||
63 | http_server.listen(1337) |
||
64 | tornado.autoreload.start() |
||
65 | tornado.ioloop.IOLoop.instance().start() |