Rev 131 |
Rev 150 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#!/usr/bin/python
# -*- coding: utf-8 -*-
import tornado.httpserver
import tornado.ioloop
import tornado.web
import tornado.autoreload
import os
import re
from tsimapiak import parsenum
from tsimapiak import dbconnector
from tsimapiak import parse
class Index(tornado.web.RequestHandler):
def get(self):
self.render("templates/index.html")
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 = parsenum.parse(num.replace(" ",""))
if numout == None:
numoutt = -1
else:
numoutt = (numout["dec"], numout["oct"])
self.render("templates/number.html", last=num, numout=numoutt)
class Restart(tornado.web.RequestHandler):
def get(self):
os.system("/usr/bin/restartnavi")
class TestDB(tornado.web.RequestHandler):
def get(self):
lis = dbconnector.getnavilist()
text = u"id | navi | infix | partofspeech<br />"
text += u"<br />".join(u" | ".join(unicode(y) for y in x) for x in lis)
self.write(text)
class Parse(tornado.web.RequestHandler):
def get(self):
self.render("templates/parse.html", last="", out=None)
def post(self):
try:
word = self.get_argument("word")
except:
self.redirect("/parse")
out = parse.parsesent(word)
self.render("templates/parse.html", last=word, out=out)
settings = {
"static_path": os.path.join(os.path.dirname(__file__), "static")
}
application = tornado.web.Application([
("/", Index),
("/number", Number),
("/restart", Restart),
("/testdb", TestDB),
("/parse", Parse)
], **settings)
if __name__ == "__main__":
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(1337)
#tornado.autoreload.start()
tornado.ioloop.IOLoop.instance().start()