def create_new_user(regname, pwd="Gl123456"): """ 创建一个用户 :param pwd: :param regname: :return: """ handle_mysql = HandleMysql() send_request = HandleRequest() url = do_config("api", "url") + "/member/register" sql = "SELECT Id FROM member WHERE MobilePhone=%s;" while True: mobilephone = handle_mysql.create_not_existed_tel() data = {"mobilephone": mobilephone, "pwd": pwd, "regname": regname} send_request(method="post", url=url, data=data) result = handle_mysql(sql=sql, args=(mobilephone,)) if result: user_id = result["Id"] break user_dict = { regname: { "Id": user_id, "regname": regname, "mobilephone": mobilephone, "pwd": pwd } } handle_mysql.close() send_request.close() return user_dict
def not_existed_tel_replace(cls, data): """ 替换参数化的未注册手机号 :param data: :return: """ do_mysql = HandleMysql() new_mobile = do_mysql.create_not_existed_tel() if re.search(cls.not_existed_tel_pattern, data): data = re.sub(cls.not_existed_tel_pattern, new_mobile, data) do_mysql.close() # 关闭数据库连接 return data