# Path: mod/_config.py

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


from .._config import gpaCacheTime
from config import VERCODE_URL, LOGIN_URL, INFO_URL
from config import STANDARD, TIME_OUT
from tornado.httpclient import HTTPRequest, AsyncHTTPClient
from BeautifulSoup import BeautifulSoup
from PIL import Image
from sqlalchemy.orm.exc import NoResultFound
from ..models.gpa_cache import GpaCache
from time import time,localtime, strftime
import tornado.web
import tornado.gen
import urllib
import json
import io
import base64
# @Date    : 2014-06-26 17:00:02
# @Author  : xindervella@gamil.com yml_bright@163.com

# import Image


class GPAHandler(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):
        username = self.get_argument('username', default=None)
        pwd = self.get_argument('password', default=None)
        status = None

        retjson = {'code':200, 'content':''}
        if not (username or pwd):
            retjson['code'] = 400
            retjson['content'] = 'params lack'
        else:
            # read from cache
            try:

# Path: mod/_config.py

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


# Path: mod/gpa/gpa_handler.py
from .._config import gpaCacheTime
from config import VERCODE_URL, LOGIN_URL, INFO_URL
from config import STANDARD, TIME_OUT
from tornado.httpclient import HTTPRequest, AsyncHTTPClient
from BeautifulSoup import BeautifulSoup
from PIL import Image
from sqlalchemy.orm.exc import NoResultFound
from ..models.gpa_cache import GpaCache
from time import time,localtime, strftime
import tornado.web
import tornado.gen
import urllib
import json
import io
import base64

# @Date    : 2014-06-26 17:00:02
# @Author  : xindervella@gamil.com yml_bright@163.com

# import Image


class GPAHandler(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):
        username = self.get_argument('username', default=None)
        pwd = self.get_argument('password', default=None)
        status = None

        retjson = {'code':200, 'content':''}
        if not (username or pwd):
            retjson['code'] = 400
            retjson['content'] = 'params lack'
        else:
            # read from cache
            try:

                status = self.db.query(GpaCache).filter(GpaCache.cardnum == username).one()