import pymysql
import random
import time
def xmxb():
with open("姓.txt","r") as f:
xing = f.read()
with open("男名.txt","r") as f:
nanming = f.read()
with open("女名.txt","r") as f:
nvming = f.read()
len_mz = 0
xb = random.randint(0,100)
sjs = random.randint(0,100)
if sjs < 60:
len_mz = 3
else:
len_mz = 2
##############################
if len_mz == 3:
if xb < 50:
xingbie = "男"
xingming = random.choice(xing)+random.choice(nanming)+random.choice(nanming)
else:
xingbie = "女"
xingming = random.choice(xing)+random.choice(nvming)+random.choice(nvming)
else:
if xb < 50:
xingbie = "男"
xingming = random.choice(xing)+random.choice(nanming)
else:
xingbie = "女"
xingming = random.choice(xing)+random.choice(nvming)
return (xingming , xingbie)
def xzbm():
db = pymysql.connect(host="www.dfs***.cn", user="*****", password="*****", db="dfzxdb")
cursor = db.cursor()
#定义SQL语句
limit = random.randint(0,614559)
sql = "select * from `xzqh-cun` limit " + str(limit) + ",1"
#执行语句
try:
#print("正在从远端服务器获取数据。。。")
cursor.execute(sql)
results = cursor.fetchall()
#print(results)
#for i in results:
#print(i[0])
#print(results)
except:
print("连接数据库错误。")
db.close()
return(results[0][6],results[0][5]+results[0][4]+results[0][3]+results[0][2]+results[0][1])
def csrq():
jn = random.randint(1,10000)
if jn == 1:
nian = random.randint(1890,1900)
if jn > 1 and jn<30:
nian = random.randint(1911,1920)
if jn >= 30 and jn < 100:
nian = random.randint(1921,1940)
if jn >= 100 and jn < 2000:
nian = random.randint(1941,1950)
if jn >= 2000 and jn < 5000:
nian = random.randint(1951,1970)
if jn >= 5000:
nian = random.randint(1971,2020)
#nian = random.randint(1890,2020)
yue = random.randint(1,12)
if yue == 2:
tian = random.randint(1,28)
if yue in [1,3,5,7,8,10,12]:
tian = random.randint(1,31)
if yue in [4,6,9,11]:
tian = random.randint(1,30)
if yue < 10:
s_month = "0" + str(yue)
else:
s_month = str(yue)
if tian < 10:
s_day = "0" + str(tian)
else:
s_day = str(tian)
#print(nian,yue,tian)
#print(str(nian),s_month,s_day)
birthday = str(nian) + s_month + s_day
return(birthday)
def sfzh(xb , birthday , xzbm):
oum , jim = [] , []
for i in range(111,995):
if i % 2 == 1:
jim.append(str(i))
else:
oum.append(str(i))
dqm = xzbm[:6]
srm = birthday
if xb == "男":
sxm = random.choice(jim)
else:
sxm = random.choice(oum)
if xb == "男" and int(birthday[:4]) < 1920:
sxm = random.choice([997,999])
if xb == "女" and int(birthday[:4]) < 1920:
sxm = random.choice([996,998])
sxm1 = str(sxm)
s17 = dqm + srm + sxm1
#7-9-10-5-8-4-2-1-6-3-7-9-10-5-8-4-2
#1-0-X -9-8-7-6-5-4-3-2
s18list=(1,0,10,9,8,7,6,5,4,3,2)
yzm = int(s17[0]) * 7 + int(s17[1]) * 9 + int(s17[2]) * 10 + int(s17[3]) * 5 + int(s17[4]) * 8 + int(s17[5]) * 4 + int(s17[6]) * 2 + int(s17[7]) + int(s17[8]) * 6 + int(s17[9]) * 3 + int(s17[10]) * 7 + int(s17[11]) * 9 + int(s17[12]) * 10 + int(s17[13]) * 5 + int(s17[14]) * 8 + int(s17[15]) * 4 +int(s17[16]) * 2
ys = yzm % 11
s18 = s18list[ys]
if s18 == 10:
s_18 = "X"
else:
s_18 = str(s18)
sfzh = s17+s_18
return(sfzh)
while True:
xm = xmxb()[0]
xb = xmxb()[1]
srm = csrq()
dqm = xzbm()
#print(dqm)
#csrq1 = csrq()
sfz = sfzh(xb,srm,str(dqm[0]))
print(xm,xb,sfz,dqm[1])
db = pymysql.connect(host = "www.dfs***.cn",user = "*****",password = "*****",db = "dfzxdb")
cursor = db.cursor()
sql = "INSERT INTO `rwxx`(xingming , xingbie , shenfenzheng , dizhi) VALUES('"+ xm +"','"+ xb +"','"+ sfz +"','"+ dqm[1] +"')"
try:
cursor.execute(sql)
db.commit()
except:
db.rollback()
print("数据库错误。")
db.close()