def paocao_refresh(): global AUTO_UPDATE_TIME print_log("Process start") db = mysql_class.MySQL(config.DB_HOST, config.DB_USER, config.DB_USER_PWD, config.DB_PORT) db.selectDb(config.DB_PAOCAO_BUFF) db.query("select * from buff_paocao where ykt = '0'") result = db.fetchAll() if result[0]['num'] == '1': db.query("select count(*) from buff_paocao where query_date < %s" % result[0]['query_date']) count = db.fetchAll() print_log("Count:%s" % count[0]['count(*)']) for i in range(0, int(count[0]['count(*)']), 1000): db.query( "select ykt from buff_paocao where query_date < %s limit %d,1000" % (result[0]['query_date'], i)) res = db.fetchAll() ret = update_paocao(res) for _update in ret: db.update("buff_paocao", _update, "ykt = '%s'" % _update['ykt']) db.commit() print_log("Success:%d" % len(ret)) print_log("Process end") t = Timer(AUTO_UPDATE_TIME, paocao_refresh) t.start()
def __init__(self, host, port): self.host = host self.port = port self.logger_runner = Logger("%s.%d"%(WORKER_LOG, self.port), logging.INFO, logging.INFO) if not os.path.exists("%s.%d"%(WORKER_LOG, self.port)):os.mknod("%s.%d"%(WORKER_LOG, self.port)) try: self.logdb = mysql_class.MySQL(config['LogDBServer']['Host'],config['LogDBServer']['User'],config['LogDBServer']['Password'],int(config['LogDBServer']['Port'])) self.logdb.select_db(config['LogDBServer']['Db']) except Exception, e: self.logdb.close() self.logger_runner.error('LogDB Error: %s'%e) sys.exit(1)
def query_paocao(cardNumber, password): cardNumber = str(int(cardNumber)) if cardNumber == '0': return 0 db = mysql_class.MySQL(config.DB_HOST, config.DB_USER, config.DB_USER_PWD, config.DB_PORT) db.selectDb(config.DB_PAOCAO_BUFF) db.query("select * from buff_paocao where ykt = '0' or ykt = " + cardNumber) result = db.fetchAll() status = refresh_status(result) print result, status if status == 0: return result[1]['num'] elif status == 1: re = query_tyx(cardNumber, password) if re.isdigit(): if result[0]['num'] == '0': db.update("buff_paocao", {'query_date': time.time()}, "ykt = 0") db.insert("buff_paocao", { 'ykt': cardNumber, 'num': re, 'query_date': time.time() }) else: re = query_tyx(cardNumber, password) if re.isdigit(): if result[0]['num'] == '0': db.update("buff_paocao", {'query_date': time.time()}, "ykt = 0") if re != result[1]['num']: db.update("buff_paocao", { 'num': 1, 'query_date': time.time() }, "ykt = 0") db.update("buff_paocao", { 'num': re, 'query_date': time.time() }, "ykt = " + cardNumber) else: db.commit() return result[1]['num'] db.commit() return re
def update_paocao(result): global COLUMN_YKT, COLUMN_PWD, ORI_DB_NAME, ORI_TABLE_NAME db = mysql_class.MySQL(config.DB_HOST, config.DB_USER, config.DB_USER_PWD, config.DB_PORT) db.selectDb(ORI_DB_NAME) query_result = [] for p in result: x = {} db.query("select %s from %s where %s = '%s'" % (COLUMN_PWD, ORI_TABLE_NAME, COLUMN_YKT, p['ykt'])) result = db.fetchAll() re = query_tyx(p['ykt'], result[0][COLUMN_PWD]) if re.isdigit(): x['ykt'] = p['ykt'] x['num'] = re x['query_date'] = int(time.time()) query_result.append(x) time.sleep(1) return query_result