最近由于进行数据库测试,需要大量的虚拟数据填充数据表,只好自己用Python造个轮子。
数据完全是虚拟的,不具备真实性,只是用来填充数据表之用途。
代码语言:javascript复制# coding:utf-8
import random
# Made by Titan!
FirstNameList = "王李张刘陈杨赵黄周吴徐孙胡朱高林何郭马罗梁宋郑谢韩唐冯于董萧程曹袁邓许傅沈曾彭吕苏卢蒋蔡贾丁魏薛叶阎余潘杜戴夏钟汪田任姜范方石姚谭廖邹熊金陆郝孔白崔康毛邱秦江史"
SecondNameList = "大学之道在明明德在亲民在止于至善知止而后有定定而后能静静而后能安安而后能虑虑而后能得物有本末事有终始知所先后则近道矣古之欲明明德于天下者先治其国欲治其国者先齐其家欲齐其家者先修其身欲修其身者先正其心欲正其心者先诚其意欲诚其意者先致其知致知在格物物格而后知至知至而后意诚意诚而后心正心正而后身修身修而后家齐家齐而后国治国治而后天下平"
textList = "归去来兮田园将芜胡不归既自以心为形役奚惆怅而独悲悟已往之不谏知来者之可追实迷途其未远觉今是而昨非舟遥遥以轻飏风飘飘而吹衣问征夫以前路恨晨光之熹微乃瞻衡宇载欣载奔僮仆欢迎稚子候门三径就荒松菊犹存携幼入室有酒盈樽引壶觞以自酌眄庭柯以怡颜倚南窗以寄傲审容膝之易安园日涉以成趣门虽设而常关策扶老以流憩时矫首而遐观云无心以出岫鸟倦飞而知还景翳翳以将入抚孤松而盘桓归去来兮请息交以绝游世与我而相违复驾言兮焉求悦亲戚之情话乐琴书以消忧农人告余以春及将有事于西畴或命巾车或棹孤舟既窈窕以寻壑亦崎岖而经丘木欣欣以向荣泉涓涓而始流善万物之得时感吾生之行休已矣乎寓形宇内复几时曷不委心任去留胡为乎遑遑欲何之富贵非吾愿帝乡不可期怀良辰以孤往或植杖而耘耔登东皋以舒啸临清流而赋诗聊乘化以归尽乐夫天命复奚疑"
AddrDict = set()
def randName():
FirstName = random.choice(FirstNameList)
SecondName = "".join(random.choice(SecondNameList)
for i in range(random.randint(1, 2)))
return FirstName SecondName
def randAddr():
AddrList = list(AddrDict)
Addr = random.choice(AddrList)
Addr = Addr.split("---")
CityName = Addr[0]
CountryList = Addr[1].split("|")
Country = random.choice(CountryList)
StreetName = "".join(random.choice(SecondNameList)
for i in range(random.randint(2, 3))) "路"
CommunityName = "".join(random.choice(textList)
for i in range(random.randint(2, 4))) "社区"
No = random.randint(1, 99)
return "河南省" CityName Country StreetName CommunityName str(No) "号"
def randBirthday():
year = random.randint(1997, 2001)
month = random.randint(1, 12)
day = random.randint(1, 27)
birthday = "{}{:0>2d}{:0>2d}".format(year, month, day)
return birthday
def randID():
birth = randBirthday()
prefixID = random.randint(400000, 411999)
subfixID = random.randint(0000, 9999)
IDCard = "{}{}{}".format(prefixID, birth, subfixID)
return IDCard
def randPhone():
second = [3, 4, 5, 7, 8][random.randint(0, 4)]
third = {
3: random.randint(0, 9),
4: [5, 7, 9][random.randint(0, 2)],
5: [i for i in range(10) if i != 4][random.randint(0, 8)],
7: [i for i in range(10) if i not in [4, 9]][random.randint(0, 7)],
8: random.randint(0, 9),
}[second]
suffix = random.randint(9999999, 100000000)
return "1{}{}{}".format(second, third, suffix)
def randPerson():
name = randName()
birth = randBirthday()
personid = randID()
phone = randPhone()
addr = randAddr()
info = "{},{},{},{},{}".format(name, birth, personid, phone, addr)
return info
if __name__ == '__main__':
with open("area.txt", encoding="utf-8") as fo:
for line in fo.readlines():
AddrDict.add(line.strip())
pass
for i in range(10):
print(randPerson())
通过randPerson函数生成的信息类似于
Area.txt来源于河南省行政规划中的区县市信息,你也可以添加你所需要的。
代码语言:javascript复制郑州市---中原区|二七区|管城回族区|金水区|上街区|惠济区|中牟县|---巩义市|荥阳市|新密市|新郑市|登封市
开封市---龙亭区|顺河回族区|鼓楼区|禹王台区|祥符区|杞县|通许县|尉氏县|兰考县
洛阳市---老城区|西工区|瀍河回族区|涧西区|吉利区---|洛龙区|孟津县|新安县|栾川县|嵩县|汝阳县|宜阳县|洛宁县|伊川县|偃师市
平顶山市---新华区|卫东区|石龙区|湛河区|宝丰县|叶县|鲁山县|郏县|舞钢市|汝州市
安阳市---文峰区|北关区|殷都区|龙安区|安阳县|汤阴县|滑县|内黄县|林州市
鹤壁市---鹤山区|山城区|淇滨区|浚县|淇县
新乡市---红旗区|卫滨区|凤泉区|牧野区|新乡县|获嘉县|原阳县|---延津县|封丘县|长垣市|卫辉市|辉县市
焦作市---解放区|中站区|马村区|山阳区|修武县|博爱县|武陟县|温县|沁阳市|孟州市
濮阳市---华龙区|清丰县|南乐县|范县|台前县|濮阳县
许昌市---魏都区|建安区|鄢陵县|襄城县|禹州市|长葛市
漯河市---源汇区|郾城区|召陵区|舞阳县|临颍县
三门峡市---湖滨区|陕州区|渑池县|卢氏县|义马市|灵宝市
南阳市---宛城区|卧龙区|南召县|方城县|西峡县|镇平县|内乡县|淅川县|社旗县|唐河县|新野县|桐柏县|邓州市
商丘市---梁园区|睢阳区|民权县|睢县|宁陵县|柘城县|虞城县|夏邑县|永城市
信阳市---浉河区|平桥区|罗山县|光山县|新县|商城县|固始县|---潢川县|淮滨县|息县
周口市---川汇区|淮阳区|扶沟县|西华县|商水县|沈丘县|郸城县|太康县|鹿邑县|项城市
驻马店市---驿城区|西平县|上蔡县|平舆县|正阳县|确山县|泌阳县|汝南县|遂平县|新蔡县
济源市---天坛街道|沁园街道|北海街道|济水街道|玉泉街道|五龙口镇|克井镇|邵原镇|坡头镇|轵城镇|承留镇|大峪镇|梨林镇|思礼镇|王屋镇|下冶镇