Rev 31 | Rev 33 | 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 | |||
31 | szabot | 37 | def getwords(): |
38 | ret = [] |
||
32 | szabot | 39 | current = u"" |
31 | szabot | 40 | db = tornado.database.Connection("127.0.0.1", "navi", user="navi", password="navi") |
41 | for row in db.query(""" |
||
42 | SELECT *, CHAR_LENGTH(navi) AS NL |
||
43 | FROM `metaWords` |
||
44 | ORDER BY NL DESC"""): |
||
45 | if row["partOfSpeech"] in (u"v.", u"vin.", u"vtr."): |
||
46 | current = unicode(row["ipa"]) |
||
47 | current = current.replace(ur"ɛ",ur"e").replace(ur".",ur"").replace(ur"ɾ",ur"r") \ |
||
14 | szabot | 48 | .replace(ur"ɪ",ur"ì").replace(ur"ˈ",ur"").replace(ur"'",ur"x") \ |
49 | .replace(ur"ŋ",ur"ng").replace(ur"j",ur"y").replace(ur"ʔ",ur"'") \ |
||
50 | .replace(ur"æ",ur"ä").replace(ur"ˌ",ur"").replace(ur"\t{ts}",ur"ts") \ |
||
16 | szabot | 51 | .replace(ur"ṛ",ur"rr").replace(ur"ḷ",ur"ll").replace(ur"k̚",ur"k ") \ |
52 | .replace(ur"p̚",ur"p ").replace(ur"t̚",ur"t ").replace(ur"'̚",ur"' ") \ |
||
53 | .replace(u"\\",ur"").replace(ur"(",ur"").replace(ur")",ur"") \ |
||
26 | szabot | 54 | .replace(ur"[",ur"").replace(ur"]",ur"").replace(ur" "," ") \ |
31 | szabot | 55 | .strip() |
56 | current = re.sub(ur" or.*","",current) |
||
57 | current = re.sub(ur"z(.*)engk(.*)e",ur"z\1enk\2e",current) |
||
58 | current = re.sub(ur"t(.*)ì(m|n)\ ",ur"t\1ìng ",current) |
||
59 | current = current.split(ur"$CDOT$") |
||
60 | if len(current) == 3: |
||
61 | current = current[0] + u"<0><1>" + current[1] + u"<2>" + current[2] |
||
62 | else: |
||
63 | urrent = current[0] + u"<0><1><2>" + current[1] |
||
64 | else: |
||
65 | current = unicode(row["navi"]) |
||
66 | ret.append([row["id"], row["navi"], current, row["partOfSpeech"]]) |
||
67 | return ret |
||
10 | szabot | 68 | |
2 | szabot | 69 | class TestDB(tornado.web.RequestHandler): |
70 | def get(self): |
||
31 | szabot | 71 | lis = getwords() |
72 | text = u"<br />".join([u"\t".join(x) for x in lis]) |
||
2 | szabot | 73 | self.write(text) |
74 | |||
75 | application = tornado.web.Application([ |
||
76 | ("/", Index), |
||
77 | ("/number", Number), |
||
78 | ("/restart", Restart), |
||
79 | ("/testdb", TestDB) |
||
80 | ]) |
||
81 | |||
82 | if __name__ == "__main__": |
||
83 | http_server = tornado.httpserver.HTTPServer(application) |
||
84 | http_server.listen(1337) |
||
85 | tornado.autoreload.start() |
||
86 | tornado.ioloop.IOLoop.instance().start() |