# 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

    def getData(self):
        ret = {'code':200,'content':''}
        try:
            content = self.db.execute("select * from wechat.boardcast where date like '"+datetime.datetime.now().strftime("%Y-%m-%d")+"%%' order by mid DESC LIMIT 1").fetchall()
            if content:
                ret['content'] = content[0]['msg']
            else:
                ret['code'] = 400
        except Exception,e:
            ret['code'] = 500
        return ret

    def today(self):
        return int(strftime('%Y%m%d', localtime(time())))
    def ismorning(self):
        if int(strftime('%H', localtime(time())))==6:
            return True
        else:
            return False

    def recognize(self, text):
        y_keyword = [u'正常跑操', u'跑操正常', u'今天继续跑操', u'今天跑操']
        result = u'今天不跑操'
        for k in y_keyword:
            if text.find(k)>=0:
                result = u'今天正常跑操'
                break
        if self.ismorning():
            try:

# 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


    def getData(self):
        ret = {'code':200,'content':''}
        try:
            content = self.db.execute("select * from wechat.boardcast where date like '"+datetime.datetime.now().strftime("%Y-%m-%d")+"%%' order by mid DESC LIMIT 1").fetchall()
            if content:
                ret['content'] = content[0]['msg']
            else:
                ret['code'] = 400
        except Exception,e:
            ret['code'] = 500
        return ret

    def today(self):
        return int(strftime('%Y%m%d', localtime(time())))
    def ismorning(self):
        if int(strftime('%H', localtime(time())))==6:
            return True
        else:
            return False

    def recognize(self, text):
        y_keyword = [u'正常跑操', u'跑操正常', u'今天继续跑操', u'今天跑操']
        result = u'今天不跑操'
        for k in y_keyword:
            if text.find(k)>=0:
                result = u'今天正常跑操'
                break
        if self.ismorning():
            try:

                status = self.db.query(PCCache).filter(PCCache.date==self.today()).one()