# Path: mod/models/data_cache.py
# class DataCache(Base):
#     __tablename__ = 'data'
#     key = Column(Integer, primary_key=True)
#     data = Column(String(10240), nullable=False)


import tornado.web
import json, base64
from ..models.data_cache import DataCache
from sqlalchemy.orm.exc import NoResultFound
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2014-12-15 18:07:58
# @Author  : yml_bright@163.com


class SchoolBusHandler(tornado.web.RequestHandler):

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

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

    def post(self):
        try:
            data = self.db.query(DataCache).filter( DataCache.key == 10001 ).one()
            self.write(base64.b64decode(data.data))
            self.db.close()
            self.finish()
        except:
            self.init_db()

# Path: mod/models/data_cache.py
# class DataCache(Base):
#     __tablename__ = 'data'
#     key = Column(Integer, primary_key=True)
#     data = Column(String(10240), nullable=False)


# Path: mod/schoolbus/handler.py
import tornado.web
import json, base64
from ..models.data_cache import DataCache
from sqlalchemy.orm.exc import NoResultFound

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2014-12-15 18:07:58
# @Author  : yml_bright@163.com


class SchoolBusHandler(tornado.web.RequestHandler):

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

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

    def post(self):
        try:
            data = self.db.query(DataCache).filter( DataCache.key == 10001 ).one()
            self.write(base64.b64decode(data.data))
            self.db.close()
            self.finish()
        except:
            self.init_db()

            data = self.db.query(DataCache).filter( DataCache.key == 10001 ).one()