China is so big, so many people, almost a mobile phone. The mobile phone number has been registered as an account of the major Internet stations. Similarly, the identity card is more so. The following is a valid mobile phone number and a social security number.
Base_dir =Os.path.dirname (Os.path.dirname (__file__)) Dc_path= Base_dir +"Districtcode.txt"# Randomly generated phone number def createphone (): Prelist=[" the","131"," the","133","134","135","136","137","138","139","147"," Max","151"," the","153","155","156","157","158","159","186","187","188"] returnRandom.choice (prelist) +"". Join (Random.choice ("0123456789") forIinchRange8) # Randomly generated ID number def getdistrictcode (): With open (Dc_path) asFile:data=file.read () districtlist= Data.split ('\ n') forNodeinchdistrictlist: #print nodeifnode[Ten: One] !=' ': State= node[Ten:].strip ()ifnode[Ten: One]==' 'and node[ A: -]!=' ': City= node[ A:].strip ()ifnode[Ten: One] ==' 'and node[ A: -]==' ': District= node[ -:].strip () code= node[0:6] Codelist.append ({" State": State," City": City,"District":d Istrict,"Code": Code}) Def gennerator ():Globalcodelist codelist= [] ifNot Codelist:getdistrictcode () ID= Codelist[random.randint (0, Len (codelist)) ['Code'] #地区项 ID= ID + str (random.randint (1930, -) ) #年份项 da= Date.today () +timedelta (Days=random.randint (1,366)) #月份和日期项 ID= ID + da.strftime ('%m%d') ID= id+ Str (random.randint ( -, -) #, sequence number simple processing I=0Count=0Weight= [7,9,Ten,5,8,4,2,1,6,3,7,9,Ten,5,8,4,2] #权重项 Checkcode={'0':'1','1':'0','2':'X','3':'9','4':'8','5':'7','6':'6','7':'5','8':'5','9':'3','Ten':'2'} #校验码映射 forIinchRange0, Len (ID)): Count= Count +int(Id[i]) *Weight[i] ID= ID + checkcode[str (count% One)] #算出校验码returnidprint createphone () print gennerator ()
ID need to download districtcode.txt this file. Http://files.cnblogs.com/files/yicaifeitian/districtcode.rar
Python generates a valid mobile phone number and ID card randomly