def __init__(self): className = self.__class__.__name__ LogUtil.initLogBatch(className) SysUtil.global_init() self.engine = SysUtil.get_engine_handle() self.db = SysUtil.get_db_handle() self.logger = logging.getLogger('batchLog_' + className)
def token2user(req,logging): token_str = req.get_header('authorization') db = SysUtil.get_db_handle() session = db() if not token_str: logging.info('no token') return None try: L = token_str.split('-') if len(L) != 4: return None uid, magicNo, expires, sha1 = L if int(expires) < time.time(): logging.info('expires') return None user = session.query(User).filter_by(userID=uid, dataStatus=GLBConfig.ENABLE).first() if user is None: logging.info('user do not exist') return None magicNo, idf = Cryptor.encrypt(user.userName, user.password, magicNo) s = '%s-%s-%s-%s' % (uid, idf, expires, settings.SECRET_KEY) if sha1 != hashlib.sha1(s.encode('utf-8')).hexdigest(): logging.info('invalid sha1') return None if userAuthCheck(session, req, user, logging) == False: logging.info('userAuthCheck Failed') return None return user except Exception as e: SysUtil.exceptionPrint(logging, e) return None finally: session.close()
def __init__(self): self.logger = logging.getLogger('serverLog') self.engine = SysUtil.get_engine_handle() self.db = SysUtil.get_db_handle()
# -*- coding: utf-8 -*- """ Created on Thu Dec 8 16:54:06 2016 @author: Administrator """ import datetime from workserver.util import SysUtil from workserver.module.models import AccountRunningBatch, MatchDataBatch, MatchInfo SysUtil.global_init() engine = SysUtil.get_engine_handle() db = SysUtil.get_db_handle() session = db() def dateRange(start,end): begin = datetime.datetime.strptime(start,"%Y-%m-%d") end = datetime.datetime.strptime(end,"%Y-%m-%d") d = begin delta = datetime.timedelta(days=1) dateList = [] while d <= end: dateList.append(d.strftime("%Y-%m-%d")) d += delta return dateList def clearData(): try: session.query(MatchDataBatch).delete()