from faker import Faker
import random

'''
简体中文：zh_CN
繁体中文：zh_TW
美国英文：en_US
英国英文：en_GB
德文：de_DE
日文：ja_JP
韩文：ko_KR
法文：fr_FR'''


class MyFaker:
    def __init__(self):
        # 选择中文语言
        self.fake = Faker("zh_CN")

    def gen_name(self):
        return self.fake.name()

    def gen_address(self):
        return self.fake.address()

    def gen_phone_number(self, num=1):
        return [self.fake.phone_number() for _ in range(num)]

    # 随机身份证
    def gen_identity_number(self):
        return self.fake.ssn()

    # 信用卡号
    def credit_card_number(self):
        return self.fake.credit_card_number()

    # MD5
    def gen_md5(self):
        return self.fake.md5()

    # sku_name
    def gen_word(self):
        return self.fake.word()

    # password
    def gen_password(self):
        return self.fake.password()

    # 随机文本

    def gen_txt(self, max_nb_chars=15):
        return self.fake.text(max_nb_chars=max_nb_chars)

    def gen_str(self, min_chars=1, max_chars=10):
        """
        范围长度内随机字符串
        :param min_chars:
        :param max_chars:
        :return:
        """
        return self.fake.pystr(min_chars=min_chars, max_chars=max_chars)

    def gen_letter(self, length=1):
        """
        生成范围长度内随机字母a-z
        :param length: 生成的长度
        :return: str
        """
        return_str = ''
        for _ in range(length):
            return_str = return_str + self.fake.random_letter()
        return return_str.lower()

    def create_num(self, start, end):
        """
        随机生成一个数字
        :param:起始范围
        :return:int
        """
        return random.randint(start, end)

    def gen_email(self):
        """
        生成虚拟测试邮箱
        """
        host_name_list=['roptaoti.com','prcf.site','curcuplas.me','hotmail.red','wpdork.com','gmailni.com']
        self.create_num(0,len(host_name_list)-1)
        host_name=host_name_list[self.create_num(0,len(host_name_list)-1)]
        # return self.fake.email()    #这种方法可能存在真实邮箱
        return self.gen_str().lower() + '@' + host_name
    def gen_word(self):
        """
        随机生成一个汉字
        :return:
        """
        head = random.randint(0xb0, 0xf7)
        body = random.randint(0xa1, 0xfe)
        val = f'{head:x} {body:x}'
        word = bytes.fromhex(val).decode('gbk')
        return word

if __name__ == '__main__':
    my_faker = MyFaker()
    # print(my_faker.gen_name())
    print(my_faker.gen_email())
