fixture.py 4.9 KB
# -*- coding: utf-8 -*-
# ======================================
# @Software: PyCharm
# @Author  : Shitou ✊
# @Time    : 2022/12/21 19:38
# @FileName: fixture.py
# ======================================
"""
获取查看数据
"""
import json
import random
import string
import radar
from common.handle_log import HandleLog

import requests
from common.handle_config import conf
from tools.handle_token import LoginToken, StudentLoginToken
from common.handle_excel import Excel
import os
import time
import random


# ==================获取json字符串==========
class SelectData(object):
    def __init__(self, url, data={"pageNumber": "1", "pageSize": "20"}):
        self.url = url
        self.data = data

    # 倒序查找返回json
    def select_list(self):
        self.url = conf.get('url', 'url_ip') + self.url
        headers = {}
        headers["Authorization"] = LoginToken.login_token()
        data = self.data
        response = requests.request(url=self.url, method="get", params=data, headers=headers)
        res = response.json()
        return res

    # 正序查找返回json
    def select_list_positive(self):
        self.url = conf.get('url', 'url_ip') + self.url
        headers = {}
        headers["Authorization"] = LoginToken.login_token()
        data = {
            "pageNumber": "1",
            "pageSize": "1000000"
        }
        response = requests.request(url=self.url, method="get", params=data, headers=headers)
        res = response.json()
        return res

    # 获取登陆学生端,返回json
    def student_select_list(self):
        self.url = conf.get('url', 'url_ip') + self.url
        headers = {}
        headers["Authorization"] = StudentLoginToken.login_token()
        data = self.data
        response = requests.request(url=self.url, method="get", params=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):
        #  随机生成年月日
        # aaa = radar.random_date("1980", "2022")
        aaa = radar.random_date("1999", "2021")
        yea = aaa.year  # 生成年
        # HandleLog.log.error("---error---aaaa的值:".format(aaa))
        # HandleLog.log.info("---info---aaaa的值:".format(aaa))
        # HandleLog.log.log("---log---aaaa的值:".format(aaa))
        # print("---print---aaaa的值:".format(aaa))

        # 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')
        return str(province[random.randint(0, len(province) - 1)] + '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("12345678")
    print(RandomIdentification().ran())
    print("123456789012345678")
    print(RandomIdentification().ran_end())

    # Val(Ran().ran_end())
    # RandomEmail.rand_email()