Subversion Repositories navi

Compare Revisions

Ignore whitespace Rev 1 → Rev 2

/tsimapiak/parsenum.py
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")
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: tsimapiak/__init__.py
===================================================================
Index: webapp/README.txt
===================================================================
--- webapp/README.txt (nonexistent)
+++ webapp/README.txt (revision 2)
@@ -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 2)
@@ -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: webapp/templates/number.html
===================================================================
--- webapp/templates/number.html (nonexistent)
+++ webapp/templates/number.html (revision 2)
@@ -0,0 +1,20 @@
+{% extends "base.html" %}
+
+{% block title %}Na'vi number translator{% end %}
+
+{% block body %}
+Na'vi number:
+
+
+
+
+{% if type(numout) == tuple %}
+Decimal: {{ numout[0] }}
+Octal: {{ numout[1] }}
+{% elif type(numout) == int %}
+Not a valid number!
+{% end %}
+
+{% end %}
/webapp/templates/number.html
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 2)
@@ -0,0 +1,32 @@
+
+
+{% block title %}Title{% end %}
+
+
+
+
+

{% 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