# Coding:utf-8
Import OS
Import Random
Import Random
Import string
Import time
From datetime import Date, datetime, Timedelta
Base_dir = Os.path.dirname (Os.path.dirname (__file__))
Print Base_dir
Dc_path = ' e:\\zsjj\\ ' + "Districtcode.txt"
Print (Dc_path)
# randomly generated mobile phone number
Def createphone ():
Prelist = ["130", "131", "132", "133", "134", "135", "136", "137", "138", "139", "147", "150", "151", "152", "153",
"155", "156", "157", "158", "159", "186", "187", "188"]
Return Random.choice (prelist) + "". Join (Random.choice ("0123456789") for I in range (8))
# Randomly generated ID number
Def getdistrictcode ():
With open (Dc_path) as file:
data = File.read ()
Districtlist = Data.split (' \ n ')
For node in districtlist:
# Print Node
If node[10:11]! = ":
State = Node[10:].strip ()
If node[10:11] = = "and node[12:13]! =":
City = Node[12:].strip ()
If node[10:11] = = "and node[12:13] = =":
district = Node[14:].strip ()
Code = Node[0:6]
Codelist.append ({' state ': State, ' City ': City, ' District ': District, ' Code ': code})
Def gennerator ():
Global Codelist
Codelist = []
If not codelist:
Getdistrictcode ()
id = codelist[random.randint (0, Len (codelist)) [' Code '] # Region entry
id = id + str (random.randint (1930, 2013)) # Year Item
da = date.today () + Timedelta (Days=random.randint (1, 366)) # Month and date entries
id = id + da.strftime ('%m%d ')
id = id + str (random.randint (100, 300)) #, sequential number simple processing
i = 0
Count = 0
Weight = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] # Weight entry
Checkcode = {' 0 ': ' 1 ', ' 1 ': ' 0 ', ' 2 ': ' X ', ' 3 ': ' 9 ', ' 4 ': ' 8 ', ' 5 ': ' 7 ', ' 6 ': ' 6 ', ' 7 ': ' 5 ', ' 8 ': ' 5 ', ' 9 ': ' 3 ',
' 10 ': ' 2 '} # Check code mapping
For I in range (0, Len (ID)):
Count = count + int (id[i]) * Weight[i]
id = id + checkcode[str (count% 11)] # Check Code
Return ID
Print Createphone ()
Print Gennerator ()
Life is short, I learn python python+selenium randomly generated mobile phone number and ID card