try: proxy_ip = update_data.copy() if where: up_where = where else: up_where = 'id=%d' % proxy_ip.pop("id") up_set = ','.join(["%s='%s'" % (key, val) for key, val in proxy_ip.items()]) if up_where and up_set: sql = "update m_proxy_ip set %s where %s" % (up_set, up_where) self.logger.info('更新表[m_proxy_ip],sql:%s', sql) affected_rows = self.DB.execute(sql) self.DB.commit() except Exception as ex: self.DB.rollback() self.logger.exception('更新表[m_proxy_ip],异常:%s', str(ex)) finally: self.DB.close() return affected_rows if __name__ == '__main__': # 日志组件 logger = LoggerFactory.get_logger() logger.info('==== proxyip_model runing start ====') logger.info('==== proxyip_model runing end ====')
def __init__(self): # DB组件 self.DB = DB() # 日志组件 self.logger = LoggerFactory.get_logger(threading.currentThread().name)
def __init__(self): # 数据库操作组件 self.DB = DB() # 日志组件 self.logger = LoggerFactory.get_logger('create-article')
def __init__(self): # 数据库操作组件 self.DB = DB() # 日志组件 self.logger = LoggerFactory.get_logger('db_import') pass
# -*- coding: utf-8 -*- """初始化数据""" __author__ = 'lijingang' import sys import time import libs.config as conf from libs.log.logger import LoggerFactory from dbs.db import DB # 日志组件 logger = LoggerFactory.get_logger('dbinit') class DBinit(object): def __init__(self): self.DB = DB() pass def create_database(self): self.DB.connect(True) self.DB.execute( "CREATE DATABASE " + conf.env.DB_NAME + " DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci") self.DB.close() pass def create_tables(self): self.DB.connect()
["%s='%s'" % (key, val) for key, val in up_data.items()]) if up_where and up_set: sql = "update m_platform_account set %s where %s" % (up_set, up_where) self.logger.info('更新表[m_platform_account],sql:%s', sql) affected_rows = self.DB.execute(sql) self.DB.commit() except Exception as ex: self.DB.rollback() self.logger.exception('更新表[m_platform_account],异常:%s', str(ex)) finally: self.DB.close() return affected_rows if __name__ == '__main__': threading.currentThread().name = 'account-model-logger' # 日志组件 logger = LoggerFactory.get_logger('account-model-logger') logger.info('==== accout_model runing start ====') accts = Account().get_refresh_accounts(is_post=0) # accts = Account().get_post_accounts() print(accts) logger.info('==== accout_model runing end ====')