# Path: mod/models/pe_models.py
# class PeDetailCache(Base):
#     __tablename__ = 'pedetail'
#     cardnum = Column(Integer, primary_key=True)
#     text = Column(String(10240))
#     date = Column(Integer, nullable=False)


from tornado.httpclient import HTTPRequest, AsyncHTTPClient,HTTPError
from sgmllib import SGMLParser
from config import loginurl1,runurl
from sqlalchemy.orm.exc import NoResultFound
from ..models.pe_models import PeDetailCache
from time import time,localtime, strftime
import json
import tornado.web
import tornado.gen
import urllib
import base64

    def end_td(self):
        self.flag -= 1

    def handle_data(self, text):
        if self.flag == 3 and self.form == 1:
            self.row.append(text)


class pedetailHandler(tornado.web.RequestHandler):
    @property
    def db(self):
        return self.application.db
    def on_finish(self):
        self.db.close()
    def get(self):
        self.write('Herald Web Service')

    @tornado.web.asynchronous
    @tornado.gen.engine
    def post(self):
        retjson = {'code':200,'content':''}
        cardnum = self.get_argument('cardnum',default=None)
        password = self.get_argument('password',default=None)
        if not (cardnum and password):
            retjson['code'] = 400
            retjson['content'] = 'params lack'
        else:
            # read from cache
            try:

# Path: mod/models/pe_models.py
# class PeDetailCache(Base):
#     __tablename__ = 'pedetail'
#     cardnum = Column(Integer, primary_key=True)
#     text = Column(String(10240))
#     date = Column(Integer, nullable=False)


# Path: mod/pe/pedetailHandler.py
from tornado.httpclient import HTTPRequest, AsyncHTTPClient,HTTPError
from sgmllib import SGMLParser
from config import loginurl1,runurl
from sqlalchemy.orm.exc import NoResultFound
from ..models.pe_models import PeDetailCache
from time import time,localtime, strftime
import json
import tornado.web
import tornado.gen
import urllib
import base64


    def end_td(self):
        self.flag -= 1

    def handle_data(self, text):
        if self.flag == 3 and self.form == 1:
            self.row.append(text)


class pedetailHandler(tornado.web.RequestHandler):
    @property
    def db(self):
        return self.application.db
    def on_finish(self):
        self.db.close()
    def get(self):
        self.write('Herald Web Service')

    @tornado.web.asynchronous
    @tornado.gen.engine
    def post(self):
        retjson = {'code':200,'content':''}
        cardnum = self.get_argument('cardnum',default=None)
        password = self.get_argument('password',default=None)
        if not (cardnum and password):
            retjson['code'] = 400
            retjson['content'] = 'params lack'
        else:
            # read from cache
            try:

                status = self.db.query(PeDetailCache).filter(PeDetailCache.cardnum == cardnum).one()