Rev 15 | Rev 17 | 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 |
||
16 | szabot | 11 | import re |
2 | szabot | 12 | |
4 | szabot | 13 | from tsimapiak.parsenum import parse |
2 | szabot | 14 | |
15 | class Index(tornado.web.RequestHandler): |
||
16 | def get(self): |
||
17 | self.redirect("/number") |
||
18 | |||
19 | class Number(tornado.web.RequestHandler): |
||
20 | def get(self): |
||
21 | self.render("templates/number.html", last="", numout=None) |
||
22 | |||
23 | def post(self): |
||
24 | try: |
||
25 | num = self.get_argument("num").strip() |
||
26 | except: |
||
27 | self.redirect("/number") |
||
28 | numout = parse(num.replace(" ","")) |
||
29 | if numout == None: |
||
30 | numout = -1 |
||
31 | self.render("templates/number.html", last=num, numout=numout) |
||
32 | |||
33 | class Restart(tornado.web.RequestHandler): |
||
34 | def get(self): |
||
35 | os.system("/usr/bin/restartnavi") |
||
36 | |||
10 | szabot | 37 | def clear(s): |
16 | szabot | 38 | s = s.replace(ur"ɛ",ur"e").replace(ur".",ur"").replace(ur"ɾ",ur"r") \ |
14 | szabot | 39 | .replace(ur"ɪ",ur"ì").replace(ur"ˈ",ur"").replace(ur"'",ur"x") \ |
40 | .replace(ur"ŋ",ur"ng").replace(ur"j",ur"y").replace(ur"ʔ",ur"'") \ |
||
41 | .replace(ur"æ",ur"ä").replace(ur"ˌ",ur"").replace(ur"\t{ts}",ur"ts") \ |
||
16 | szabot | 42 | .replace(ur"ṛ",ur"rr").replace(ur"ḷ",ur"ll").replace(ur"k̚",ur"k ") \ |
43 | .replace(ur"p̚",ur"p ").replace(ur"t̚",ur"t ").replace(ur"'̚",ur"' ") \ |
||
44 | .replace(u"\\",ur"").replace(ur"(",ur"").replace(ur")",ur"") \ |
||
45 | .replace(ur"[",ur"").replace(ur"]",ur"") \ |
||
46 | .replace(ur"$\cdot$",ur"").strip() |
||
47 | s = re.sub(ur" or.*","",s) |
||
48 | return s |
||
10 | szabot | 49 | |
2 | szabot | 50 | class TestDB(tornado.web.RequestHandler): |
51 | def get(self): |
||
9 | szabot | 52 | text = u"" |
2 | szabot | 53 | db = tornado.database.Connection("127.0.0.1", "navi", user="navi", password="navi") |
6 | szabot | 54 | for thing in db.query(""" |
10 | szabot | 55 | SELECT *, CHAR_LENGTH(navi) AS NL |
6 | szabot | 56 | FROM `metaWords` |
16 | szabot | 57 | ORDER BY NL DESC |
58 | WHERE partOfSpeech IN ('v.', 'vin.', 'vtr,')"""): |
||
14 | szabot | 59 | text += unicode(thing["navi"]) + u" - " + clear(unicode(thing["ipa"])) + u" - " + unicode(thing.navi == clear(unicode(thing["ipa"]))) + u"<br />" |
2 | szabot | 60 | self.write(text) |
61 | |||
62 | application = tornado.web.Application([ |
||
63 | ("/", Index), |
||
64 | ("/number", Number), |
||
65 | ("/restart", Restart), |
||
66 | ("/testdb", TestDB) |
||
67 | ]) |
||
68 | |||
69 | if __name__ == "__main__": |
||
70 | http_server = tornado.httpserver.HTTPServer(application) |
||
71 | http_server.listen(1337) |
||
72 | tornado.autoreload.start() |
||
73 | tornado.ioloop.IOLoop.instance().start() |