Commit cda497f027f990b6da61d2a1d168466cf3c0bb7a

Authored by 175930106
Committed by liujiqiang
1 parent 1c28e1e2

维护Faker的代码

Showing 1 changed file with 69 additions and 10 deletions
src/commons/Faker.py
1 1 #!/usr/bin/python
2 2 # -*- coding: UTF-8 -*-
  3 +import random
3 4 from faker import Factory
4 5  
5   -
6 6 class random_data():
7 7  
8 8 def __init__(self, type='zh_CN'):
9 9 self.type = type
10 10 self.fake = Factory().create(self.type)
  11 +
  12 + def date(self):
  13 + "随机时间"
  14 + return self.fake.date(pattern="%Y-%m-%d")
11 15  
12 16 def name(self):
13 17 "随机姓名"
14 18 return self.fake.name()
  19 +
  20 + def identity_card(self):
  21 + "随机姓名"
  22 + return self.fake.ssn(min_age=18, max_age=90)
  23 +
  24 + def plate(self):
  25 + "随机车牌号"
  26 + return self.fake.license_plate()
  27 +
  28 + def plate_cn(self,plate_len=6):
  29 + char0='京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽赣粤青藏川宁琼'
  30 + char1='ABCDEFGHJKLMNPQRSTUVWXYZ'#车牌号中没有I和O,可自行百度
  31 + char2='1234567890'
  32 + len0=len(char0)-1
  33 + len1 = len(char1) - 1
  34 + len2 = len(char2) - 1
  35 + ########
  36 + code = ''
  37 + index0 = random.randint(0,len0 )
  38 + index1 = random.randint(0,len1)
  39 + code += char0[index0]
  40 + code += char1[index1]
  41 + for i in range(0, plate_len-1):
  42 + index2 = random.randint(1, len2)
  43 + code += char2[index2]
  44 + return(code)
  45 +
  46 + def country(self):
  47 + "随机国家代码"
  48 + return self.fake.country()
  49 +
  50 + def province(self):
  51 + "随机省份"
  52 + return self.fake.province()
  53 +
  54 + def city(self):
  55 + "随机城市"
  56 + return self.fake.city_suffix()
  57 +
  58 + def district(self):
  59 + "随机街道"
  60 + return self.fake.district()
15 61  
16 62 def address(self):
17   - "随机姓名"
  63 + "随机地址全称"
18 64 return self.fake.address()
19 65  
20 66 def phone_number(self):
21   - "随机姓名"
  67 + "随机手机号"
22 68 return self.fake.phone_number()
23 69  
24 70 def email(self):
25   - "随机姓名"
  71 + "随机邮件"
26 72 return self.fake.email()
27 73  
28 74 def longitude(self):
29   - "随机姓名"
  75 + "随机经度"
30 76 return self.fake.longitude()
31 77  
32 78 def latitude (self):
33   - "随机姓名"
  79 + "随机维度"
34 80 return self.fake.latitude ()
35 81  
36 82 def credit_card_number (self):
37   - "随机姓名"
  83 + "随机卡号"
38 84 return self.fake.credit_card_number ()
39 85  
40 86  
41 87  
42   -# a=random_data()
43   -#
44   -# print a.credit_card_number()
  88 +a=random_data()
  89 +print(a.date())
  90 +print(a.name())
  91 +print(a.identity_card())
  92 +print(a.plate())
  93 +print(a.plate_cn(6))
  94 +print(a.country())
  95 +print(a.province())
  96 +print(a.city())
  97 +print(a.district())
  98 +print(a.address())
  99 +print(a.phone_number())
  100 +print(a.email())
  101 +print(a.longitude())
  102 +print(a.latitude())
  103 +print(a.credit_card_number())
45 104  
... ...