# Path: mod/models/pc_cache.py
# class PCCache(Base):
#     __tablename__ = 'pc'
#     date = Column(Integer, primary_key=True)
#     text = Column(String(255), nullable=False)
#     lastdate = Column(Integer)


from config import *
from tornado.httpclient import HTTPRequest, HTTPClient,HTTPError
from bs4 import BeautifulSoup
from ..models.pc_cache import PCCache
from sqlalchemy.orm.exc import NoResultFound
from time import time, localtime, strftime
import tornado.web
import tornado.gen
import datetime
import urllib, re
import json
import base64
import rsa,tea,traceback
import os, hashlib, re, tempfile, binascii, base64
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2015-10-26 14:46:50
# @Author  : jerry.liangj@qq.com


class PCHandler(tornado.web.RequestHandler):

    @property
    def db(self):
        return self.application.db
    def get(self):
        self.write('Herald Web Service')

    def post(self):
        retjson = {'code':200, 'content':u'暂时关闭'}
        try:
            if self.ismorning():
                status = self.db.query(PCCache).filter( PCCache.date == self.today(),PCCache.lastdate+180>int(time())).one()
                retjson['content'] = base64.b64decode(status.text)
                self.db.close()
                self.write(json.dumps(retjson, ensure_ascii=False, indent=2))
                self.finish()

# Path: mod/models/pc_cache.py
# class PCCache(Base):
#     __tablename__ = 'pc'
#     date = Column(Integer, primary_key=True)
#     text = Column(String(255), nullable=False)
#     lastdate = Column(Integer)


# Path: mod/pc/handler.py
from config import *
from tornado.httpclient import HTTPRequest, HTTPClient,HTTPError
from bs4 import BeautifulSoup
from ..models.pc_cache import PCCache
from sqlalchemy.orm.exc import NoResultFound
from time import time, localtime, strftime
import tornado.web
import tornado.gen
import datetime
import urllib, re
import json
import base64
import rsa,tea,traceback
import os, hashlib, re, tempfile, binascii, base64

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2015-10-26 14:46:50
# @Author  : jerry.liangj@qq.com


class PCHandler(tornado.web.RequestHandler):

    @property
    def db(self):
        return self.application.db
    def get(self):
        self.write('Herald Web Service')

    def post(self):
        retjson = {'code':200, 'content':u'暂时关闭'}
        try:
            if self.ismorning():
                status = self.db.query(PCCache).filter( PCCache.date == self.today(),PCCache.lastdate+180>int(time())).one()
                retjson['content'] = base64.b64decode(status.text)
                self.db.close()
                self.write(json.dumps(retjson, ensure_ascii=False, indent=2))
                self.finish()

            else: