# 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

            # read from cache
            try:
                status = self.db.query(PhylabCache).filter( PhylabCache.cardnum ==  number ).one()
                if status.date > int(time())-phylabCacheTime and status.text != '*':
                    self.write(base64.b64decode(status.text))
                    self.db.close()
                    self.finish()
                    return
            except NoResultFound:
                status = PhylabCache(cardnum=number, text='*', date=int(time()))
                self.db.add(status)
                try:
                    self.db.commit()
                except:
                    self.db.rollback()

            if int(term[3:5]) - int(number[3:5]) == 1:
                curType = cur_type_up
                retjson['content'] = {'基础性实验(上)':[],'基础性实验(上)选做':[],'文科及医学实验':[],'文科及医学实验选做':[]}
            else:
                curType = cur_type_down
                retjson['content'] = {'基础性实验(下)':[],'基础性实验(下)选做':[],'文科及医学实验':[],'文科及医学实验选做':[]}

            client = AsyncHTTPClient()
            loginValues['ctl00$cphSltMain$UserLogin1$txbUserCodeID'] = number
            loginValues['ctl00$cphSltMain$UserLogin1$txbUserPwd'] = password

            try:
                request = HTTPRequest(
                        LOGIN_URL,

# 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

            # read from cache
            try:
                status = self.db.query(PhylabCache).filter( PhylabCache.cardnum ==  number ).one()
                if status.date > int(time())-phylabCacheTime and status.text != '*':
                    self.write(base64.b64decode(status.text))
                    self.db.close()
                    self.finish()
                    return
            except NoResultFound:
                status = PhylabCache(cardnum=number, text='*', date=int(time()))
                self.db.add(status)
                try:
                    self.db.commit()
                except:
                    self.db.rollback()

            if int(term[3:5]) - int(number[3:5]) == 1:
                curType = cur_type_up
                retjson['content'] = {'基础性实验(上)':[],'基础性实验(上)选做':[],'文科及医学实验':[],'文科及医学实验选做':[]}
            else:
                curType = cur_type_down
                retjson['content'] = {'基础性实验(下)':[],'基础性实验(下)选做':[],'文科及医学实验':[],'文科及医学实验选做':[]}

            client = AsyncHTTPClient()
            loginValues['ctl00$cphSltMain$UserLogin1$txbUserCodeID'] = number
            loginValues['ctl00$cphSltMain$UserLogin1$txbUserPwd'] = password

            try:
                request = HTTPRequest(
                        LOGIN_URL,

                        method='GET',
