fixture.py
3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# -*- coding: utf-8 -*-
# ======================================
# @Software: PyCharm
# @Author : Shitou ✊
# @Time : 2022/12/21 19:38
# @FileName: fixture.py
# ======================================
"""
获取查看数据
"""
import random
import string
import requests
from common.handle_config import conf
from tools.handle_token import LoginToken
from common.handle_excel import Excel
import os
import time
import random
"""
获取json字符串
"""
class SelectData(object):
def __init__(self, url):
self.url = url
def select_list(self):
self.url = conf.get('url', 'url_ip') + self.url
headers = {}
headers["Authorization"] = LoginToken.login_token()
data = {
"pageNumber": "0",
"pageSize": "3"
}
response = requests.request(url=self.url, method="get", json=data, headers=headers)
res = response.json()
return res
"""
随机生成手机号
"""
class RandomPhone:
# 随机生成手机号
@staticmethod
def random_phone():
for k in range(1):
prelist = ["155", "136", "173", "133"]
return random.choice(prelist) + "".join(random.choice("0123456789") for i in range(8))
"""
随机生成身份证号
"""
class RandomIdentification(object):
def ran(self):
# 随机生成年月日
yea = random.randint(1933, int(time.strftime("%Y"))) # 生成年
# 生成月
mon = random.randint(1, 12)
ran_mon = '0' + str(mon) if mon < 10 else mon
# 生成日
day = random.randint(1, 27)
ran_day = '0' + str(day) if day < 10 else day
return str(yea) + str(ran_mon) + str(ran_day)
def ran_value(self):
# 生成年月日后的三位数
value = random.randint(10, 199)
if value < 100:
return "0" + str(value)
else:
return str(value)
def ran_area(self):
# 随机取生成前六位
province = (
'11', '12', '13', '14', '15', '21', '22', '23', '31', '32', '33', '34', '35', '36', '37', '41', '42',
'43', '44', '45', '46', '50', '51', '52', '53', '54', '61', '62', '63', '64', '65', '66')
return str(province[random.randint(0, len(province))] + '0101')
def ran_end(self):
# 组成前17位数字
ran = self.ran_area() + self.ran() + self.ran_value()
# 前17位每位需要乘上的系数,用字典表示,比如第一位需要乘上7,最后一位需要乘上2
coe = {1: 7, 2: 9, 3: 10, 4: 5, 5: 8, 6: 4, 7: 2, 8: 1, 9: 6, 10: 3, 11: 7, 12: 9, 13: 10, 14: 5, 15: 8, 16: 4,
17: 2}
summat = 0
# 循环计算前17位每位乘上系数之后的和
for i in range(17):
summat = summat + int(ran[i:i + 1]) * coe[i + 1]
# 前17位每位乘上系数之后的和除以11得到的余数对照表,比如余数是0,那第18位就是1
mat = {0: '1', 1: '0', 2: 'X', 3: '9', 4: '8', 5: '7', 6: '6', 7: '5', 8: '4', 9: '3', 10: '2'}
return ran + mat[summat % 11]
"""
随机生成邮箱
"""
class RandomEmail(object):
@staticmethod
def rand_email():
email_len = random.randint(1, 99999999999)
# print(str(email_len) + "@163.com")
return str(email_len) + "@163.com"
if __name__ == '__main__':
print(RandomIdentification().ran_end())
# Val(Ran().ran_end())
# RandomEmail.rand_email()