-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_chars.py
278 lines (232 loc) · 8.25 KB
/
generate_chars.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# -*- coding:utf-8 -*-
import numpy as np
import os
import re
import random
import time
from create_corpus import create_amount_in_word,create_amount_in_figure,create_date_single
class CharsGenerator(object):
def __init__(self, char_dir=None, charsSet=None, charLen=1):
self.char_dir=char_dir
self.len=charLen
self.charsSet=charsSet
#出生
def persion_birth(self,path=None):
while True:
date1 = (2010, 1, 1, 0, 0, 0, -1, -1, -1)
time1 = time.mktime(date1)
date2 = (2050, 1, 1, 0, 0, 0, -1, -1, -1)
time2 = time.mktime(date2)
random_time = random.uniform(time1, time2) # uniform返回随机实数 time1 <= time < time2
abc = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(random_time))
numtype = random.randint(0, 2)
numtype = 4
if numtype == 0:
acadgd = abc.split()[0].replace('-', '')
if numtype == 1:
acadgd = abc.split()[0].replace('-', ' ')
if numtype == 2:
acadgd = abc.split()[0].replace('-', '.')
if numtype == 3:
acadgd = abc.split()[0].replace('-', '/')
if numtype == 4:
aldfa = abc.split()[0].split('-')
acadgd = aldfa[0] + u"年" + aldfa[1] + u"月" + aldfa[2] + u"日"
yield acadgd
#姓名
def persion_name(self,path):
f = open(path, "r")
lists = []
abdc = []
i = 0
while True:
i = i + 1
if i == 1028295:
break
# print i
line = f.readline()
# print i,"saa"
if line:
# print line
str = line.decode('utf-8')
# print str,len(str)
matchObj = re.match(r'http://.+resgain.net/name/(.+).html', str, re.M | re.I)
if matchObj:
# print "matchObj.group() : ", matchObj.group()
# print "matchObj.group(1) : ", matchObj.group(1)
abdc.append(matchObj.group(1))
# print len(abdc), "www"
f.close()
while True:
yield random.choice(abdc)
#公民身份号码
def persion_id(self,path=None):
while True:
d1 = random.randint(1, 6)
if d1 == 1 or d1 == 5 or d1 == 6:
d2 = random.randint(0, 5)
elif d1 == 2 or d1 == 4:
d2 = random.randint(0, 3)
elif d1 == 3:
d2 = random.randint(0, 7)
d3to4 = random.randint(1, 70)
d5to6 = random.randint(1, 99)
d_birth_year = random.randint(1935, 2017)
d_birth_month = random.randint(1, 12)
if d_birth_month == 2:
d_birth_day = random.randint(1, 28)
else:
d_birth_day = random.randint(1, 30)
d15to17 = random.randint(100, 700)
d18 = random.randint(0, 9)
yield ('%d''%d''%02d''%02d''%02d''%02d''%02d''%02d''%d' \
% (d1, d2, d3to4, d5to6, d_birth_year, \
d_birth_month, d_birth_day, d15to17, d18))
#电汇凭证--------
#NO
def dianhuipingzheng_id(self,path=None):
while True:
yield str(random.randint(10000000, 99999999))
#账号
def dianhuipingzheng_num(self,path=None):
#b = random.randint(1000000000000, 9000000000000)
pass
#全称
def dianhuipingzheng_name(self,path=None):
pass
#开户许可证----------
#核准号
def kaihuxukezheng_num(self,path=None):
while True:
s = []
for ch in xrange(0x41, 0x5A):
s.append(unichr(ch))
a = random.choice(s)
b = random.randint(100000000000000, 900000000000000)
yield (a + ('%d' % b))
# 开户银行
def kaihuxukezheng_bank(self,path=None):
return self.shuiwudengjizheng_1(path)
#税务登记证--------
#纳税人名称
def shuiwudengjizheng_1(self,path=None):
f = open(path)
lists = []
abdc = []
i = 0
while True:
i = i + 1
if i == 20002:
break
# print i
line = f.readline()
# print i,"saa"
if line:
if i % 2 == 0:
pass
else:
str = line.strip()
str = str.decode('utf-8')
abdc.append(str)
# print i
# print str,len(str)
f.close()
while True:
yield random.choice(abdc)
#地址
def shuiwudengjizheng_2(self,path=None):
return self.shuiwudengjizheng_1(path)
#银行卡号------------
def yinhangcard_num(self,length):
while True:
leng=random.choice(length)
if leng == 16:
# 16位
id = random.randint(1000000000000000, 9999999999999999)
elif leng==19:
id = random.randint(1000000000000000000, 9999999999999999999)
else:
raise ValueError("chars' length must be 19 or 16")
yield str(id)
#营业执照------------
#住所
def yingyezhichao_addr(self,path=None):
return self.shuiwudengjizheng_1(path)
#注册资本
def yingyezhichao_money(self,path=None):
for num in create_amount_in_figure(prefix=u''):
yield (('%s' % num) + u"万元")
#注册资本 大写金额
def yingyezhichao_money_big(self,path=None):
return create_amount_in_word()
def date_capital(self,path=None):
for display_text in create_date_single():
display_text = display_text.strip()
display_text = display_text.strip(u"日")
testuncodelist = []
temp = display_text.split("年")
testuncodelist.append(temp[0])
testuncodelist.extend(temp[1].split(u"月"))
yield testuncodelist
def loans_num(self,path=None):
all_chars = u'0123456789'
chars_list = []
# print '正在生成小写金额样本...'
while True:
if random.uniform(0,1)<0.8:
integer_part=random.randint(-9,9)
integer_part=max(0,integer_part)
else:integer_part=random.randint(10,100)
strr=str(integer_part)+"."+str(random.randint(0,9))+str(random.randint(0,9))
strr=strr.decode("utf-8")
yield strr
#增值税专用发票----------
#""
def zhuangyongtax_none(self,path=None):
while True:
b = random.randint(1000000000, 9999999999)
yield ('%d' % b)
#No
def zhuangyongtax_No(self,path=None):
while True:
b = random.randint(10000000, 99999999)
yield ('%d' % b)
#¥
def zhuangyongtax_money(self,path=None):
while True:
b = random.randint(0, 99999999)
c = random.randint(0, 99)
yield (u"¥" + ('%d' % b) + "." + ('%d' % c))
#名称
def zhuangyongtax_name(self,path=None):
return self.shuiwudengjizheng_1(path)
#开票日期
def zhuangyongtax_date(self,path=None):
return self.persion_birth(path)
#组织机构代码证-----------------
#代码
def zujijigou_code(self,path=None):
while True:
b = random.randint(00000000, 99999999)
c = random.randint(0, 9)
yield (('%d' % b) + '-' + ('%d' % c))
#机构名称
def zujijigou_addr(self,path=None):
return self.shuiwudengjizheng_1(path)
def signature_num(self,path=None):
s = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "C", "K", "N", "P", "R", "U", "V", "X", "Y"]
while True:
yield "".join(random.sample(s,16))
#纳税人名称
def test_dot(self,path=None):
lists = []
with open(path) as ff:
for line in ff:
line=line.strip()
lists.append(line.decode('utf-8'))
while True:
yield "".join(random.sample(lists, 40))
def number(self,path=None):
while True:
b = random.randint(10000000, 99999999)
yield ('%d' % b)