Rev 70 |
Rev 77 |
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
from tsimapiak import parse2
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 = parsenum.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):
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").strip()
except:
self.redirect("/parse")
out = parse.parsefix(word)
self.render("templates/parse.html", last=word, out=out)
class Parse2(tornado.web.RequestHandler):
def get(self):
self.render("templates/parse2.html", last="", out=None)
def post(self):
try:
word = self.get_argument("word").strip()
except:
self.redirect("/parse2")
out = parse2.parseword(word)
self.render("templates/parse2.html", last=word, out=out)
application = tornado.web.Application([
("/", Index),
("/number", Number),
("/restart", Restart),
("/testdb", TestDB),
("/parse", Parse),
("/parse2", Parse2)
])
if __name__ == "__main__":
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(1337)
#tornado.autoreload.start()
tornado.ioloop.IOLoop.instance().start()