import random
import os
#文件目录
data_dir="/home/data"
isExists=os.path.exists(data_dir)
if not isExists:
os.makedirs(data_dir)
print("Dir '"+data_dir+"' Created")
#每个批次数据量
data_numspertime=2400
#生成数据的批次数
data_times=1
data_nums = data_numspertime * data_times
datafile_name="man_area_info.txt"
datalines_str=''
sAreaName='xx市'
sAreaLevel='3'
iAreaType='2'
sNodeCode='8810'
sTopAreaCode='891000'
iAreaState='0'
dAreaBeginDate='1900/1/1'
dAreaEndDate='2999/12/31'
sRemark=''
sSiteUpFlag=''
sSiteUpTime=''
with open(data_dir+'/'+datafile_name, 'w+', encoding='utf-8') as f:
f.write("sAreaCode,sRealAreaCode,sAreaName,sAreaLevel,iAreaType,sNodeCode,sTopAreaCode,iAreaState,dAreaBeginDate,dAreaEndDate,sRemark,sSiteUpFlag,sSiteUpTime\n")
for i in range(0, data_nums):
sRealAreaCode=random.randrange(10, 99)*100 + random.randrange(10, 30)
sAreaCode=sRealAreaCode*100
dataline=str(sAreaCode)+','+str(sRealAreaCode)+','+sAreaName+','+sAreaLevel+','+iAreaType+','+sNodeCode+','+sTopAreaCode+','+iAreaState+','+dAreaBeginDate+','+dAreaEndDate+','+sRemark+','+sSiteUpFlag+','+sSiteUpTime+"\n"
datalines_str += dataline
f.write(datalines_str)
==============
import random
import os
import threading
#文件目录
data_dir="/home/data"
isExists=os.path.exists(data_dir)
if not isExists:
os.makedirs(data_dir)
print("Dir '"+data_dir+"' Created")
#每个批次数据量
data_numspertime=4000
#生成数据的批次数
data_times=5
datafile_prefix="acc_personal_account_sub_info_"
datafile_suffix=".txt"
sAccNo='843121000000042945713abc9'
sCardInfo='333'
sMedia='01'
sSubCardLogoutDate=''
sSubCardState='01'
sPartValue='2017105100098013'
sbankarea='bul_1000'
idmsg='999'
imonth='99'
#单个写入一个该batchid对应文件中
def wfilePerBatch(batchid):
datalines_str=''
with open(data_dir+'/'+datafile_prefix+str(batchid)+datafile_suffix, 'w+', encoding='utf-8') as f:
f.write("sAccNo,sAccBankCode,sCardInfo,dEndDate,sMedia,sSubCardLogoutDate,sSubCardState,sPartValue,sbankarea,idmsg,imonth\n")
for i in range(0, data_numspertime):
sBankTypeCode=random.randrange(100, 999)
sBankAreaCode=random.randrange(100, 600)*1000
sAccBankCode=str(sBankTypeCode)+str(sBankAreaCode)+'0'+str(random.randrange(10, 100))
month=random.randrange(13)
day=random.randrange(29)
date1='2018-'+str(month)+'-'+str(day)
dEndDate_list=[None,'',date1]
dEndDate=str(random.choice(dEndDate_list))
dataline=sAccNo+','+sAccBankCode+','+sCardInfo+','+dEndDate+','+sMedia+','+sSubCardLogoutDate+','+sSubCardState+','+sPartValue+','+sbankarea+','+idmsg+','+imonth+"\n"
datalines_str += dataline
f.write(datalines_str)
#根据批次号启动多个线程并发生产数据
for batchid in range(0, data_times):
threadx = threading.Thread(target=wfilePerBatch, args=(batchid,))
threadx.start()
threadx.join()
print('退出所有线程')