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