/webapp/templates/number.html |
---|
0,0 → 1,20 |
{% extends "base.html" %} |
{% block title %}Number translator{% end %} |
{% block body %} |
<b>Na'vi number:</b><br /> |
<form action="/number" method="post"> |
<input id="num" name="num" type="text" value="{{last}}" style="width: 100%;" /> |
<input name="btn" type="submit" value="Translate!" /> |
</form> |
{% if type(numout) == tuple %} |
Decimal: {{ numout[0] }}<br /> |
Octal: {{ numout[1] }} |
{% elif type(numout) == int %} |
Not a valid number! |
{% end %} |
<script type="text/javascript"> |
document.getElementById("num").focus(); |
</script> |
{% end %} |
Property changes: |
Added: svn:executable |
## -0,0 +1 ## |
+* |
\ No newline at end of property |
Index: webapp/templates/base.html |
=================================================================== |
--- webapp/templates/base.html (nonexistent) |
+++ webapp/templates/base.html (revision 3) |
@@ -0,0 +1,37 @@ |
+ |
+ |
+ |
+ |
+body { |
+ background: #145179; |
+ color: #FFF6D0; |
+ font-family: papyrus,"Georgia","Times New Roman",serif; |
+ padding: 0px; |
+ border: 0px; |
+ margin: 0px; |
+} |
+h1 { |
+ text-align: center; |
+ font-size: 52px; |
+} |
+h1 { |
+ text-align: center; |
+ font-size: 24px; |
+} |
+#center { |
+ background: #2594DE; |
+ width: 760px; |
+ margin-left: auto; |
+ margin-right: auto; |
+ padding: 20px; |
+} |
+ |
+ |
+ |
+ |
+Tsim Apiak |
+{% block title %}Title{% end %} |
+{% block body %}Body{% end %} |
+ |
+ |
+ |
/webapp/templates/base.html |
---|
Property changes: |
Added: svn:executable |
## -0,0 +1 ## |
+* |
\ No newline at end of property |
Index: webapp/README.txt |
=================================================================== |
--- webapp/README.txt (nonexistent) |
+++ webapp/README.txt (revision 3) |
@@ -0,0 +1,3 @@ |
+This is a webapp for TsimApiak written for the Tornado Web Server. |
+ |
+To use it you have to put the tsimapiak directory inside this dir, and run main.py. |
Index: webapp/main.py |
=================================================================== |
--- webapp/main.py (nonexistent) |
+++ webapp/main.py (revision 3) |
@@ -0,0 +1,55 @@ |
+#!/usr/bin/python |
+# -*- coding: utf-8 -*- |
+ |
+import tornado.httpserver |
+import tornado.ioloop |
+import tornado.web |
+import tornado.autoreload |
+import tornado.database |
+ |
+import os |
+ |
+from navi.parsenum import parse |
+ |
+class Index(tornado.web.RequestHandler): |
+ def get(self): |
+ self.redirect("/number") |
+ |
+class Number(tornado.web.RequestHandler): |
+ def get(self): |
+ self.render("templates/number.html", last="", numout=None) |
+ |
+ def post(self): |
+ try: |
+ num = self.get_argument("num").strip() |
+ except: |
+ self.redirect("/number") |
+ numout = parse(num.replace(" ","")) |
+ if numout == None: |
+ numout = -1 |
+ self.render("templates/number.html", last=num, numout=numout) |
+ |
+class Restart(tornado.web.RequestHandler): |
+ def get(self): |
+ os.system("/usr/bin/restartnavi") |
+ |
+class TestDB(tornado.web.RequestHandler): |
+ def get(self): |
+ text = "" |
+ db = tornado.database.Connection("127.0.0.1", "navi", user="navi", password="navi") |
+ for thing in db.query("SELECT * FROM test"): |
+ text = " ".join((text, str(thing.id) + " - " + thing.asd)) |
+ self.write(text) |
+ |
+application = tornado.web.Application([ |
+ ("/", Index), |
+ ("/number", Number), |
+ ("/restart", Restart), |
+ ("/testdb", TestDB) |
+]) |
+ |
+if __name__ == "__main__": |
+ http_server = tornado.httpserver.HTTPServer(application) |
+ http_server.listen(1337) |
+ tornado.autoreload.start() |
+ tornado.ioloop.IOLoop.instance().start() |
Index: tsimapiak/parsenum.py |
=================================================================== |
--- tsimapiak/parsenum.py (nonexistent) |
+++ tsimapiak/parsenum.py (revision 3) |
@@ -0,0 +1,81 @@ |
+#!/usr/bin/python |
+# -*- coding: utf-8 -*- |
+ |
+import re |
+ |
+num = [u"kew", |
+ u"'aw", |
+ u"mune", |
+ u"pxey", |
+ u"tsìng", |
+ u"mrr", |
+ u"pukap", |
+ u"kinä"] |
+ |
+rem = [u"aw", |
+ u"mun", |
+ u"pey", |
+ u"sìng", |
+ u"mrr", |
+ u"fu", |
+ u"hin"] |
+ |
+base = [u"", |
+ u"me", |
+ u"pxe", |
+ u"tsì", |
+ u"mrr", |
+ u"pu", |
+ u"ki"] |
+ |
+ |
+numre = \ |
+ u"^(?:(" + "|".join(base) + u")zazam??)?" + \ |
+ u"(?:(" + "|".join(base) + u")vozam??)?" + \ |
+ u"(?:(" + "|".join(base) + u")zam??)?" + \ |
+ u"(?:(" + "|".join(base) + u")vo(?:l(?=a|))?)?" + \ |
+ u"((?:" + "|".join(rem) + u")|" + \ |
+ u"(?:" + "|".join(num) + u"))?$" |
+numre = re.compile(numre) |
+ |
+def parse(numin): |
+ if type(numin) != unicode: |
+ return None |
+ if numin == u"": |
+ return None |
+ numin = numin.replace(u"í",u"ì").replace(u"á",u"ä") |
+ try: |
+ mat = numre.match(numin).groups() |
+ except: |
+ return None |
+ numout = 0 |
+ numoct = 0 |
+ try: |
+ numout += rem.index(mat[4]) + 1 |
+ numoct += rem.index(mat[4]) + 1 |
+ except: |
+ try: |
+ numout += num.index(mat[4]) |
+ numoct += num.index(mat[4]) |
+ except: pass |
+ try: |
+ numout += (base.index(mat[3]) + 1) * 8 |
+ numoct += (base.index(mat[3]) + 1) * 10 |
+ except: pass |
+ try: |
+ numout += (base.index(mat[2]) + 1) * 8**2 |
+ numoct += (base.index(mat[2]) + 1) * 10**2 |
+ except: pass |
+ try: |
+ numout += (base.index(mat[1]) + 1) * 8**3 |
+ numoct += (base.index(mat[1]) + 1) * 10**3 |
+ except: pass |
+ try: |
+ numout += (base.index(mat[0]) + 1) * 8**4 |
+ numoct += (base.index(mat[0]) + 1) * 10**4 |
+ except: pass |
+ return numout, numoct |
+ |
+ |
+if __name__ == "__main__": |
+ print parse(u"mrrvolaw") |
/tsimapiak/parsenum.py |
---|
Property changes: |
Added: svn:executable |
## -0,0 +1 ## |
+* |
\ No newline at end of property |
Index: tsimapiak/__init__.py |
=================================================================== |