# Path: mod/_config.py

# 
# Path: mod/models/phylab_cache.py
# class PhylabCache(Base):
#     __tablename__ = 'phylab'
#     cardnum = Column(Integer, primary_key=True)
#     text = Column(String(4096), nullable=False)
#     date = Column(Integer, nullable=False)


from .._config import phylabCacheTime
from config import *
from tornado.httpclient import HTTPRequest, AsyncHTTPClient,HTTPClient
from BeautifulSoup import BeautifulSoup
from ..models.phylab_cache import PhylabCache
from sqlalchemy.orm.exc import NoResultFound
from time import time, localtime, strftime
import tornado.web
import tornado.gen
import urllib
import json, base64
import datetime
import traceback

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2014-10-26 12:46:36
# @Author  : yml_bright@163.com


class PhylabHandler(tornado.web.RequestHandler):

    @property
    def db(self):
        return self.application.db

    def get(self):
        self.write('Herald Web Service')

    @tornado.web.asynchronous
    @tornado.gen.engine
    def post(self):
        number = self.get_argument('number',default=None)
        password = self.get_argument('password',default=None)
        term = self.get_argument('term',default=None)

        retjson = {'code':200, 'content':''}
        if not number or not password or not term:
            retjson['code'] = 400
            retjson['content'] = 'params lack'
        else:
            # read from cache
            try:

# Path: mod/_config.py

# 
# Path: mod/models/phylab_cache.py
# class PhylabCache(Base):
#     __tablename__ = 'phylab'
#     cardnum = Column(Integer, primary_key=True)
#     text = Column(String(4096), nullable=False)
#     date = Column(Integer, nullable=False)


# Path: mod/phylab/handler.py
from .._config import phylabCacheTime
from config import *
from tornado.httpclient import HTTPRequest, AsyncHTTPClient,HTTPClient
from BeautifulSoup import BeautifulSoup
from ..models.phylab_cache import PhylabCache
from sqlalchemy.orm.exc import NoResultFound
from time import time, localtime, strftime
import tornado.web
import tornado.gen
import urllib
import json, base64
import datetime
import traceback

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2014-10-26 12:46:36
# @Author  : yml_bright@163.com


class PhylabHandler(tornado.web.RequestHandler):

    @property
    def db(self):
        return self.application.db

    def get(self):
        self.write('Herald Web Service')

    @tornado.web.asynchronous
    @tornado.gen.engine
    def post(self):
        number = self.get_argument('number',default=None)
        password = self.get_argument('password',default=None)
        term = self.get_argument('term',default=None)

        retjson = {'code':200, 'content':''}
        if not number or not password or not term:
            retjson['code'] = 400
            retjson['content'] = 'params lack'
        else:
            # read from cache
            try:

                status = self.db.query(PhylabCache).filter( PhylabCache.cardnum ==  number ).one()
