Beispiel #1
0
 def __init__(self):
     # 连接数据库,创建游标。
     # 1、建立连接
     self.conn = pymysql.connect(host=conf.get("mysql", "host"),
                                 port=conf.getint("mysql", "port"),
                                 user=conf.get("mysql", "user"),
                                 password=conf.get("mysql", "password"),
                                 database=conf.get("mysql", "database"),
                                 charset="utf8",
                                 cursorclass=pymysql.cursors.DictCursor)
     # 2、创建游标
     self.cur = self.conn.cursor()
Beispiel #2
0
def get_old_phone():
    """
    从配置文件获取指定的用户名和密码
    确保此帐号,在系统当中是注册了的。
    返回:用户名和密码。
    """
    from qianchengdai.Conmon.handle_config import conf
    user = conf.get("general_user","user")
    passwd = conf.get("general_user","passwd")
    # 如果数据库查找到user,就直接返回。如果没有,则调用注册接口注册一个。
    # 不管注册与否,直接调用注册接口。
    send_requests("POST","member/register",{"mobile_phone":user,"pwd":passwd})
    return user,passwd
Beispiel #3
0
def __pre_url(url):
    """
    拼接接口的url地址。
    """
    base_url = conf.get("server", "base_url")
    if url.startswith("/"):
        return base_url + url
    else:
        return base_url + "/" + url
Beispiel #4
0
    def __init__(self, file_name=None):
        # 设置输出级别、输出渠道、输出日志格式
        # super().__init__(name,level)
        super().__init__(conf.get("log", "name"), conf.get("log", "level"))

        # 日志格式
        fmt = '%(asctime)s %(name)s %(levelname)s %(filename)s-%(lineno)d line:%(message)s'
        formatter = logging.Formatter(fmt)

        # 控制台渠道
        handle1 = logging.StreamHandler()
        handle1.setFormatter(formatter)
        self.addHandler(handle1)

        if file_name:
            # 文件渠道
            handle2 = logging.FileHandler(file_name, encoding="utf-8")
            handle2.setFormatter(formatter)
            self.addHandler(handle2)
Beispiel #5
0
        # super().__init__(name,level)
        super().__init__(conf.get("log", "name"), conf.get("log", "level"))

        # 日志格式
        fmt = '%(asctime)s %(name)s %(levelname)s %(filename)s-%(lineno)d line:%(message)s'
        formatter = logging.Formatter(fmt)

        # 控制台渠道
        handle1 = logging.StreamHandler()
        handle1.setFormatter(formatter)
        self.addHandler(handle1)

        if file_name:
            # 文件渠道
            handle2 = logging.FileHandler(file_name, encoding="utf-8")
            handle2.setFormatter(formatter)
            self.addHandler(handle2)


# 是否需要写入文件
if conf.getboolean("log", "file_ok"):
    file_name = os.path.join(logs_dir, conf.get("log", "file_name"))
else:
    file_name = None

logger = MyLogger(file_name)

if __name__ == '__main__':

    logger.info("1111111111111111")