idCard
def create_idcard(self):
"""
身份证
"""
cur = datetime.now()
id = str(random.choice(city_code_list()))
id = id + str(random.randint(cur.year - 55, cur.year - 25))
da = date.today() + timedelta(days=random.randint(1, 366))
id = id + da.strftime('%m%d')
id = id + str(random.randint(100, 300))
id = id + self._generateCheckCode(id)
return id
name
SURNAME_LIST = [
'赵', '钱', '孙', '李', '周', '吴', '郑', '王', '冯', '陈', '褚', '卫', '蒋',
'沈', '韩', '杨', '朱', '秦', '尤', '许', '何', '吕', '施', '张', '孔', '曹',
'严', '华', '金', '魏', '陶', '姜', '戚', '谢', '邹', '喻', '柏', '水', '窦',
'章', '云', '苏', '潘', '葛', '奚', '范', '彭', '郎', '鲁', '韦', '昌', '马',
'苗', '凤', '花', '方', '俞', '任', '袁', '柳', '酆', '鲍', '史', '唐', '费',
'廉', '岑', '薛', '雷', '贺', '倪', '汤', '滕', '殷', '罗', '毕', '郝', '邬',
'安', '常', '乐', '于', '时', '傅', '皮', '卞', '齐', '康', '伍', '余', '元',
'卜', '顾', '孟', '平', '黄', '和', '穆', '萧', '尹', '姚', '邵', '堪', '汪',
'祁', '毛', '禹', '狄', '米', '贝', '明', '臧', '计', '伏', '成', '戴', '谈',
'宋', '茅', '庞', '熊', '纪', '舒', '屈', '项', '祝', '董', '梁', '欧阳', '太史',
'端木', '上官', '司马', '东方', '独孤', '南宫', '万俟', '闻人', '夏侯', '诸葛', '尉迟',
'公羊', '赫连', '澹台', '皇甫', '宗政', '濮阳', '公冶', '太叔', '申屠', '公孙', '慕容',
'仲孙', '钟离', '长孙', '宇文', '司徒', '鲜于', '司空', '闾丘', '子车', '亓官', '司寇',
'巫马', '公西', '颛孙', '壤驷', '公良', '漆雕', '乐正', '宰父', '谷梁', '拓跋', '夹谷',
'轩辕', '令狐', '段干', '百里', '呼延', '东郭', '南门', '羊舌', '微生', '公户', '公玉',
'公仪', '梁丘', '公仲', '公上', '公门', '公山', '公坚', '左丘', '公伯', '西门', '公祖',
'第五', '公乘', '贯丘', '公皙', '南荣', '东里', '东宫', '仲长', '子书', '子桑', '即墨',
'达奚', '褚师', '吴铭'
]
FIRSTNAME_LIST = [
'梦琪', '忆柳', '之桃', '慕青', '问兰', '尔岚', '元香', '初夏', '沛菡', '傲珊', '曼文',
'乐菱', '痴珊', '恨玉', '惜文', '香寒', '新柔', '语蓉', '海安', '夜蓉', '涵柏', '水桃',
'醉蓝', '春儿', '语琴', '从彤', '傲晴', '语兰', '又菱', '碧彤', '元霜', '怜梦', '紫寒',
'妙彤', '曼易', '南莲', '紫翠', '雨寒', '易烟', '如萱', '若南', '寻真', '晓亦', '向珊',
'慕灵', '以蕊', '寻雁', '映易', '雪柳', '孤岚', '笑霜', '海云', '凝天', '沛珊', '寒云',
'冰旋', '宛儿', '绿真', '盼儿', '晓霜', '碧凡', '夏菡', '曼香', '若烟', '半梦', '雅绿',
'冰蓝', '灵槐', '平安', '书翠', '翠风', '香巧', '代云', '梦曼', '幼翠', '友巧', '听寒',
'梦柏', '醉易', '访旋', '亦玉', '凌萱', '访卉', '怀亦', '笑蓝', '春翠', '靖柏', '夜蕾',
'冰夏', '梦松', '书雪', '乐枫', '念薇', '靖雁', '寻春', '恨山', '从寒', '忆香', '觅波',
'静曼', '凡旋', '以亦', '念露', '芷蕾', '千兰', '新波', '代真', '新蕾', '雁玉', '冷卉',
'紫山', '千琴', '恨天', '傲芙', '盼山', '怀蝶', '冰兰', '山柏', '翠萱', '恨松', '问旋',
'从南', '白易', '问筠', '如霜', '半芹', '丹珍', '冰彤', '亦寒', '寒雁', '怜云', '寻文',
'乐丹', '翠柔', '谷山', '之瑶', '冰露', '尔珍', '谷雪', '乐萱', '涵菡', '海莲', '傲蕾',
'青槐', '冬儿', '易梦', '惜雪', '宛海', '之柔', '夏青', '亦瑶', '妙菡', '春竹', '痴梦',
'紫蓝', '晓巧', '幻柏', '元风', '冰枫', '访蕊', '南春', '芷蕊', '凡蕾', '凡柔', '安蕾',
'天荷', '含玉', '书兰', '雅琴', '书瑶', '春雁', '从安', '夏槐', '念芹', '怀萍', '代曼',
'幻珊', '谷丝', '秋翠', '白晴', '海露', '代荷', '含玉', '书蕾', '听白', '访琴', '灵雁',
'秋春', '雪青', '乐瑶', '含烟', '涵双', '平蝶', '雅蕊', '傲之', '灵薇', '绿春', '含蕾',
'从梦', '从蓉', '初丹', '听兰', '听蓉', '语芙', '夏彤', '凌瑶', '忆翠', '幻灵', '怜菡',
'紫南', '依珊', '妙竹', '访烟', '怜蕾', '映寒', '友绿', '冰萍', '惜霜', '凌香', '芷蕾',
'雁卉', '迎梦', '元柏', '代萱', '紫真', '千青', '凌寒', '紫安', '寒安', '怀蕊', '秋荷']
def full_name(self):
"""
姓名
"""
sur = random.choice(SURNAME_LIST)
name = random.choice(FIRSTNAME_LIST)
return "{0}{1}".format(sur, name)
phone/mobile
def create_phone(self):
"""
创建手机号码
"""
prelist = [
"130", "131", "132", "133", "134", "135", "136", "137", "138",
"139", "147", "150", "151", "152", "153", "155", "156", "157",
"158", "159", "186", "187", "188", "189"
]
return random.choice(prelist) + "".join(
random.choice("0123456789") for i in range(8))
bankNo
CARDBIN_LIST = [623350, 623208, 621283, 621212, 621293, 621294, 621342, 621343, 621364, 621394, 623309, 623040, 621782,
621041, 622274, 622273, 622771, 622772, 621215, 621638, 621648, 621231, 621334, 621395, 621249, 622348,
621248, 621488, 621598, 621082, 621081, 589970, 524094, 526410, 434062, 552245, 421349, 621466, 622966,
621499, 622700, 621621, 623698, 623699, 623686, 621218, 621475, 622988, 621476, 623229, 623260, 623321,
623263, 623571, 623572, 623573, 623575, 623668, 900003, 623258, 623014, 624100, 624200, 623094, 623255,
621210, 624301, 624402, 623700, 624000, 621670, 621618, 620058, 621281, 621733, 621732, 620085, 621691,
421393, 472067, 472068, 427571, 427570, 421865, 415599, 622615, 622619, 6226171, 622616, 622620, 622618,
900010, 900000, 402791, 427028, 427038, 548259, 620516, 622202, 622203, 621762, 621240, 621414, 621372,
622926, 622927, 622928, 622929, 622930, 622931, 621378, 621300, 621376, 621730, 621379, 621720, 621763,
621369, 621761, 621749, 621434, 621370, 621374, 621781, 6213771621750, 621731, 622660, 621404, 622008,
622013, 623901, 621741, 434061, 620706, 622821, 623524, 622826, 621669, 622182, 621467, 622150, 620200,
620604, 620902, 622823, 623206, 620060, 620107, 622280, 621080, 621284, 623251, 621673, 623211, 621084,
621487, 621083, 621765, 622382, 621764, 621371, 621734, 621367, 621433, 621719, 623524, 623524, 623524,
623524, 623184, 623569, 623586, 622944, 622949, 622670, 622671, 622668, 622661, 621202, 622672, 622674,
622673, 621302, 621303, 621305, 621306, 621307, 621309, 621311, 621211, 621315, 621304, 621405, 621406,
621407, 621408, 621409, 621410, 621502, 621317, 621603, 621604, 621605, 621511, 621602, 621608, 621609,
621610, 621611, 621613, 621614, 621615, 621616, 621617, 621607, 621606, 621804, 621807, 621813, 621814,
621817, 621901, 621904, 621905, 621906, 621908, 621909, 621910, 621911, 621912, 621913, 621915, 622002,
621903, 622004, 621559, 621723, 621721, 621558, 621288, 623062, 622208, 621227, 622200, 621722, 621225,
621226, 620302, 620402, 620403, 620404, 620406, 620407, 620409, 6204101, 620405, 620411, 620412, 620502,
620503, 620408, 620512, 620602, 620607, 620611, 620612, 620704, 620707, 620708, 620709, 620710, 620609,
620712, 620713, 620714, 620802, 620711, 620904, 620905, 621001, 621103, 621105, 621106, 621102, 621107,
621203, 621204, 621205, 621206, 621207, 621208, 621209, 622180, 622187, 625586, 622189, 620529, 621464,
955100, 621095, 621098, 621096, 622151, 622188, 622199, 622181, 620062, 621285, 621797, 621799, 621798,
621599, 621674, 621622, 623219, 623034, 622669, 621402, 621612, 621907, 622015, 622305, 623218, 622517,
623015, 621423, 620086, 622622, 622770, 620501, 621375, 623669, 623683, 627025, 627026, 621662, 621297,
627027, 627028, 623683, 623052, 623056, 621661, 621788, 621786, 621785, 621787, 621790, 621789, 621725,
621666, 621668, 6216671, 621660, 621672
]
def create_bankcardno(self):
"""
银行卡,储蓄卡19位
尾号不能是019
"""
return str(random.choice(CARDBIN_LIST)) + "".join(
random.choice("0123456789") for i in range(12)) + "".join(
random.choice("2345678") for i in range(1))
综合脚本
"""
测试数据主文件
created by ywp 2018-1-16
"""
import random
import string
import time
from datetime import date, datetime, timedelta
from dateutil.relativedelta import relativedelta
from chinacitycode import city_code_list
from chinesename import SURNAME_LIST, FIRSTNAME_LIST
from chinesecardbin import CARDBIN_LIST
class PersonalInfo:
"""
个人信息
"""
def create_phone(self):
"""
创建手机号码
"""
prelist = [
"130", "131", "132", "133", "134", "135", "136", "137", "138",
"139", "147", "150", "151", "152", "153", "155", "156", "157",
"158", "159", "186", "187", "188", "189"
]
return random.choice(prelist) + "".join(
random.choice("0123456789") for i in range(8))
def sur(self):
"""
姓
"""
return random.choice(SURNAME_LIST)
def name(self):
"""
名字
"""
return random.choice(FIRSTNAME_LIST)
def full_name(self):
"""
姓名
"""
sur = random.choice(SURNAME_LIST)
name = random.choice(FIRSTNAME_LIST)
return "{0}{1}".format(sur, name)
def _generateCheckCode(self, idCard):
"""
身份证最后1位,校验码
"""
def haoma_validate(idCard):
if type(idCard) in [str, list, tuple]:
if len(idCard) == 17:
return True
raise Exception('Wrong argument')
if haoma_validate(idCard):
if type(idCard) == str:
seq = map(int, idCard)
elif type(idCard) in [list, tuple]:
seq = idCard
t = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
s = sum(map(lambda x: x[0] * x[1], zip(t, map(int, seq))))
b = s % 11
bd = {
0: '1',
1: '0',
2: 'X',
3: '9',
4: '8',
5: '7',
6: '6',
7: '5',
8: '4',
9: '3',
10: '2'
}
return bd[b]
def create_idcard(self):
"""
身份证
"""
cur = datetime.now()
id = str(random.choice(city_code_list()))
id = id + str(random.randint(cur.year - 55, cur.year - 25))
da = date.today() + timedelta(days=random.randint(1, 366))
id = id + da.strftime('%m%d')
id = id + str(random.randint(100, 300))
id = id + self._generateCheckCode(id)
return id
def create_bankcardno(self):
"""
银行卡,储蓄卡19位
尾号不能是019
"""
return str(random.choice(CARDBIN_LIST)) + "".join(
random.choice("0123456789") for i in range(12)) + "".join(
random.choice("2345678") for i in range(1))
def fourelements(self):
"""
四要素
"""
return {
"id": self.create_idcard(),
"name": self.full_name(),
"phone": self.create_phone(),
"bankNo": self.create_bankcardno()
}
class DateTimeUtil:
"""
封装一些常用的日期/时间
"""
def get_sql_dt(self, days=0):
'''
获取当前日期时间,格式'2015-07-08 08:51:59'
'''
onedatetime = datetime.now() + timedelta(days=days)
return onedatetime.strftime(r'%Y-%m-%d %H:%M:%S')
def get_noseparators_dt(self, days=0):
'''
获取当前日期时间,格式'20150708085159'
'''
onedatetime = datetime.now() + timedelta(days=days)
return onedatetime.strftime(r'%Y%m%d%H%M%S')
def get_request_no(self):
"""
获取时间流水号
"""
requestno = self.get_noseparators_dt() + "".join(
random.choice(string.ascii_letters) for i in range(4))
return requestno
def strtodate(self, datestr):
'''
仅限yy-mm-dd 格式
'''
tmp = [int(x) for x in datestr.split('-')]
return datetime(tmp[0], tmp[1], tmp[2])
def get_today(self):
'''
获取当前日期时间,格式'20170821'
'''
return time.strftime(r'%Y%m%d', time.localtime(time.time()))
def get_tomorrow(self):
'''
获取当前日期时间,格式'20170821'
'''
tomorrow = datetime.now() + timedelta(days=+1)
return tomorrow.strftime(r'%Y%m%d')
def get_yesterday(self):
'''
获取当前日期时间,格式'20170821'
'''
yesterday = datetime.now() + timedelta(days=-1)
return yesterday.strftime(r'%Y%m%d')
def get_oneday(self, days):
'''
通过日期偏移量获取某一天,格式'2017-08-21'
'''
tmp = datetime.now() + timedelta(days)
return tmp.strftime("%Y-%m-%d")
def get_timexint(self):
"""
获取时间戳
"""
return str(time.time()).replace('.', '')
def get_aftermonth(self, months):
'''
通过月数偏移量获取某一天,格式'2017-08-21'
'''
tmp = datetime.now() + relativedelta(months=months)
return tmp.strftime("%Y-%m-%d")
def get_day(self):
'''
获取今天是这个月的第几天
'''
return str(date.today().day)
if __name__ == '__main__':
TMP = PersonalInfo()
print(TMP.fourelements())