Faker.py 2.8 KB
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import random
from faker import Factory

class random_data():
    
        def __init__(self, type='zh_CN'):
            self.type = type
            self.fake = Factory().create(self.type)
   
        def date(self):
            "随机时间"
            return self.fake.date(pattern="%Y-%m-%d")
            
        def name(self):
            "随机姓名"
            return self.fake.name()
        
        def identity_card(self):
            "随机姓名"
            return self.fake.ssn(min_age=18, max_age=90)

        def plate(self):
            "随机车牌号"
            return self.fake.license_plate()
        
        def plate_cn(self,plate_len=6):
            char0='京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽赣粤青藏川宁琼'
            char1='ABCDEFGHJKLMNPQRSTUVWXYZ'#车牌号中没有I和O,可自行百度
            char2='1234567890'
            len0=len(char0)-1
            len1 = len(char1) - 1
            len2 = len(char2) - 1
            ########
            code = ''
            index0 = random.randint(0,len0 )
            index1 = random.randint(0,len1)
            code += char0[index0]
            code += char1[index1]
            for i in range(0, plate_len-1):
                index2 = random.randint(1, len2)
                code += char2[index2]
            return(code)
    
        def country(self):
            "随机国家代码"
            return self.fake.country()

        def province(self):
            "随机省份"
            return self.fake.province()
        
        def city(self):
            "随机城市"
            return self.fake.city_suffix()

        def district(self):
            "随机街道"
            return self.fake.district()

        def address(self):
            "随机地址全称"
            return self.fake.address()

        def phone_number(self):
            "随机手机号"
            return self.fake.phone_number()

        def email(self):
            "随机邮件"
            return self.fake.email()
        
        def longitude(self):
            "随机经度"
            return self.fake.longitude()   
        
        def latitude (self):
            "随机维度"
            return self.fake.latitude ()       

        def credit_card_number (self):
            "随机卡号"
            return self.fake.credit_card_number ()



a=random_data()
print(a.date())
print(a.name()) 
print(a.identity_card()) 
print(a.plate()) 
print(a.plate_cn(6)) 
print(a.country()) 
print(a.province()) 
print(a.city()) 
print(a.district()) 
print(a.address())
print(a.phone_number())
print(a.email())
print(a.longitude())
print(a.latitude())
print(a.credit_card_number())