Exemplo n.º 1
0
def modif_date(data):
    """
    初始化请求时修改时间
    :param data:
    :return:
    """
    sev_time = TimeFormat.get_month_ago(1)
    sev_month = '-'.join(sev_time.split('-')[:2])
    sev_day = sev_time.split(' ')[0]
    sev_hms = data["calls"][0]['items'][0]['time'].split(' ')[-1]
    month_start_date, month_end_date = TimeFormat.get_FirstAndLastDay_month(
        sev_day)
    time_sec = sev_day + ' ' + sev_hms
    data["bills"][0]['bill_month'] = sev_month
    data["bills"][0]['bill_start_date'] = month_start_date
    data["bills"][0]['bill_end_date'] = month_end_date
    data["calls"][0]['bill_month'] = sev_month
    data["calls"][0]['items'][0]['time'] = time_sec
    data["smses"][0]['bill_month'] = sev_month
    data["smses"][0]['items'][0]['time'] = time_sec.replace(' ', '-')
Exemplo n.º 2
0
def modif(data, modif_key, modif_value):
    """
    修改请求数据
    :param data: 请求数据
    :param modif_key:  修改请求数据参数
    :param modif_value: 修改值
    :return:
    carrier: 运营商类型 (联通、移动、电信)
    open_time: 开户时长 (天)
    sex:男,女
    age: 年龄
    total_fee:账期内所有费用
    web_fee:网络流量消费金额(分)
    voice_fee:通话消费金额(分)
    sms_fee:短信消费金额(分)
    extra_service_fee:增值业务消费金额(分)
    extra_fee:其它消费金额(分)
    base_fee:基础消费金额
    sms_cnt:短信次数 (数字)
    sms_fees:短信费用
    location:朋友圈中心城市
    peer_number:朋友联系数量
    location_type:号码类型;国内通话
    dial_type:主叫,被叫 DAIL,DAILED
    duration: 通话时长(秒)
    fee: 通话费用
    time: 通话时段 (早晨,上午,中午,下午,傍晚,晚上,凌晨,深夜)
        早晨(5:30:00-9:00:00)
        上午(9:00:00-11:30:00)
        中午(11:30:00-13:30:00)
        下午(13:30:00-17:30:00)
        傍晚(17:30:00-19:30:00)
        晚上(19:30:00-23:30:00)
        凌晨(23:30:00-01:30:00)
        深夜(01:30:00-05:30:00)
    time2: 通话时段
        早晨(5:30-11:30)
        中午(11:30-13:30)
        下午(13:30-17:30)
        晚上(17:30-23:30)
        凌晨(23:30-5:30)
    time3: 通话时段 0-7点,不用输入参数修改值
    total_size:通话次数
    bill_month:通话月份 (7,1,3,6)
    calls: 通话信息条数 (数字)
    """
    if re.sub('\s+', '', modif_value) == '':
        modif_value = 'null'
    if modif_key == 'carrier':
        # modif_value 输入 联通、移动、电信
        if modif_value in carriers.keys():
            modif_value = carriers[modif_value]
        data["carrier"] = modif_value
    elif modif_key == 'open_time':
        # 输入数字,距离当前时间的天数
        if modif_value.isdigit():
            modif_value = TimeFormat.get_day_around(-int(modif_value))
        data["open_time"] = modif_value
    elif modif_key == 'sex':
        # 输入男、女,自动生成 idcard
        idcard = list(data["idcard"])
        if modif_value == '女':
            v = random.choice('02468')
            idcard[16] = str(v)
            data["idcard"] = ''.join(idcard)
        elif modif_value == '男':
            v = random.choice('13579')
            idcard[16] = str(v)
            data["idcard"] = ''.join(idcard)
        else:
            data["idcard"] = modif_value
    elif modif_key == 'age':
        # 输入年龄,自动生成 idcard
        if modif_value.isdigit():
            idcard = list(data["idcard"])
            time_now = TimeFormat.getnow_day()
            year, month, day = time_now.split('-')
            y = int(year) - int(modif_value)
            idcard[6:14] = ''.join([str(y), month, day])
            data["idcard"] = ''.join(idcard)
        else:
            data["idcard"] = modif_value
    elif modif_key == 'city':
        data["city"] = modif_value
    elif modif_key == 'total_fee':
        data["bills"][0]["total_fee"] = modif_value
    elif modif_key == 'web_fee':
        data["bills"][0]["web_fee"] = modif_value
    elif modif_key == 'voice_fee':
        data["bills"][0]["voice_fee"] = modif_value
    elif modif_key == 'sms_fee':
        data["bills"][0]["sms_fee"] = modif_value
    elif modif_key == 'extra_service_fee':
        data["bills"][0]["extra_service_fee"] = modif_value
    elif modif_key == 'extra_fee':
        data["bills"][0]["extra_fee"] = modif_value
    elif modif_key == 'base_fee':
        data["bills"][0]["base_fee"] = modif_value
    elif modif_key == 'sms_cnt':
        # 输入数字, 自动生成对应数字的短信条数
        if modif_value.isdigit():
            sms = data['smses'][0]
            data['smses'] = [sms for _ in range(int(modif_value))]
        else:
            data['smses'] = []
    elif modif_key == 'sms_fees':
        data['smses'][0]['items'][0]['fee'] = modif_value
    elif modif_key == 'location':
        data["calls"][0]['items'][0]['location'] = modif_value
    elif modif_key == 'peer_number':
        data["calls"][0]['items'][0]['peer_number'] = modif_value
    elif modif_key == 'location_type':
        data["calls"][0]['items'][0]['location_type'] = modif_value
    elif modif_key == 'dial_type':
        # 输入 DAIL 或者 DAILED
        calls = data["calls"][0]
        call = copy.deepcopy(calls)
        call['items'][0]['dial_type'] = modif_value
        data["calls"][0] = call
    elif modif_key == 'duration':
        if modif_value.isdigit():
            modif_value = int(modif_value)
        data["calls"][0]['items'][0]['duration'] = modif_value
    elif modif_key == 'fee':
        data["calls"][0]['items'][0]['fee'] = modif_value
    elif modif_key == 'time':
        # 输入时间段
        #         早晨(5:30:00-9:00:00)
        #         上午(9:00:00-11:30:00)
        #         中午(11:30:00-13:30:00)
        #         下午(13:30:00-17:30:00)
        #         傍晚(17:30:00-19:30:00)
        #         晚上(19:30:00-23:30:00)
        #         凌晨(23:30:00-01:30:00)
        #         深夜(01:30:00-05:30:00)
        if modif_value in ('早晨', '上午', '中午', '下午', '傍晚', '晚上', '凌晨', '深夜'):
            sev_time = data["calls"][0]['items'][0]['time']
            sev_day = sev_time.split(' ')[0]
            data["calls"][0]['items'][0]['time'] = get_time_step(
                sev_day, modif_value)
        else:
            data["calls"][0]['items'][0]['time'] = modif_value
    elif modif_key == 'time2':
        # 输入时间段
        #         早晨(5:30-11:30)
        #         中午(11:30-13:30)
        #         下午(13:30-17:30)
        #         晚上(17:30-23:30)
        #         凌晨(23:30-5:30)
        if modif_value in ('早晨', '中午', '下午', '晚上', '凌晨'):
            sev_time = data["calls"][0]['items'][0]['time']
            sev_day = sev_time.split(' ')[0]
            data["calls"][0]['items'][0]['time'] = get_time_step2(
                sev_day, modif_value)
        else:
            data["calls"][0]['items'][0]['time'] = modif_value
    elif modif_key == 'time3':
        # 输入时间段, 不用输入修改参数值, 直接获取 0-7点
        sev_time = data["calls"][0]['items'][0]['time']
        sev_day = sev_time.split(' ')[0]
        data["calls"][0]['items'][0]['time'] = get_time_step07(sev_day)
    elif modif_key == 'total_size':
        if modif_value.isdigit():
            modif_value = int(modif_value)
        data["calls"][0]['total_size'] = modif_value
    elif modif_key == 'bill_month':
        # 输入修改的月份 7,1,3,6; 7代表7天,其余的都是月份
        times = data["calls"][0]['items'][0]['time']
        time_hmc = times.split(' ')[-1]
        if modif_value == '7':
            start_day = TimeFormat.get_day_around(-7)
            bill_month = '-'.join(start_day.split('-')[:2])
            month_start_date, month_end_date = TimeFormat.get_FirstAndLastDay_month(
                bill_month)
            e_time = start_day + ' ' + time_hmc
            e_time_num = int(TimeFormat.string_toTimestamp_13(e_time))
            n_hms = TimeFormat.getnow().split(' ')[-1]
            n_time_num = int(
                TimeFormat.string_toTimestamp_13(start_day + ' ' + n_hms))
            if e_time_num <= n_time_num:
                e_time = TimeFormat.get_day_around(1,
                                                   start_day) + ' ' + time_hmc
            data["calls"][0]['bill_month'] = bill_month
            data["calls"][0]['items'][0]['time'] = e_time
            data["smses"][0]['bill_month'] = bill_month
            data["smses"][0]['items'][0]['time'] = e_time.replace(' ', '-')
            data["bills"][0]['bill_month'] = bill_month
            data["bills"][0]['bill_start_date'] = month_start_date
            data["bills"][0]['bill_end_date'] = month_end_date
        elif modif_value in ('1', '3', '6'):
            month_day = TimeFormat.get_month_day_ago(int(modif_value))
            year, month, day = month_day.split('-')
            bill_month = year + '-' + month
            month_start_date, month_end_date = TimeFormat.get_FirstAndLastDay_month(
                bill_month)
            data["calls"][0]['bill_month'] = bill_month
            e_time = month_day + ' ' + time_hmc
            e_time_num = int(TimeFormat.string_toTimestamp_13(e_time))
            n_hms = TimeFormat.getnow().split(' ')[-1]
            n_time_num = int(
                TimeFormat.string_toTimestamp_13(month_day + ' ' + n_hms))
            if e_time_num <= n_time_num:
                e_time = TimeFormat.get_day_around(1,
                                                   month_day) + ' ' + time_hmc
            data["calls"][0]['items'][0]['time'] = e_time
            data["smses"][0]['bill_month'] = bill_month
            data["smses"][0]['items'][0]['time'] = e_time.replace(' ', '-')
            data["bills"][0]['bill_month'] = bill_month
            data["bills"][0]['bill_start_date'] = month_start_date
            data["bills"][0]['bill_end_date'] = month_end_date
        else:
            data["calls"][0]['bill_month'] = modif_value
            data["smses"][0]['bill_month'] = modif_value
            data["bills"][0]['bill_month'] = modif_value
    elif modif_key == 'calls':
        # 输入数字,自动生成通话条数
        if modif_value.isdigit():
            calls = data["calls"][0]
            call = copy.deepcopy(calls)
            data["calls"] = [call for _ in range(int(modif_value))]
        else:
            data["calls"] = []