コード例 #1
0
def check_in(user):
    check_dict_list = []
    
    # 登录获取token用于打卡
    token = get_token(user['phone'], user['password'], user['device_id'])
    
    if not token:
        errmsg = f"{user['phone'][:4]},获取token失败,打卡失败,"
        log.warning(errmsg)
        check_dict_list.append({"status": 0, "errmsg": errmsg})
        return check_dict_list
    
    # 获取个人信息
    user_info = get_user_info(token)
    if not user_info:
        errmsg = f"{user['phone'][:4]},获取个人信息失败,打卡失败"
        log.warning(errmsg)
        check_dict_list.append({"status": 0, "errmsg": errmsg})
        return check_dict_list
    log.info(f'{user_info["username"][0]}-{user_info["school"]},获取个人信息成功')
    
    healthy1_check_config = user.get('healthy_checkin', {}).get('one_check')
    healthy2_check_config = user.get('healthy_checkin', {}).get('two_check')
    if healthy1_check_config.get('enable'):
        # 第一类健康打卡
        
        # 获取第一类健康打卡的参数
        post_dict = get_healthy1_check_post_json(token, healthy1_check_config.get('templateid', "pneumonia"))
        
        # 合并配置文件的打卡信息
        merge_post_json(post_dict, healthy1_check_config.get('post_json', {}))
        
        healthy1_check_dict = healthy1_check_in(token, user['phone'], post_dict)
        check_dict_list.append(healthy1_check_dict)
    elif healthy2_check_config.get('enable'):
        # 第二类健康打卡
        
        # 获取第二类健康打卡参数
        post_dict = get_healthy2_check_posh_json(token)
        
        # 合并配置文件的打卡信息
        if not healthy2_check_config['post_json']['latitude'] and not healthy2_check_config['post_json']['longitude']:
            post_dict['latitude'] = ""
            post_dict['longitude'] = ""
            log.info('当前打卡未设置经纬度,后台会将此次打卡计为手动打卡(学校没做要求可不管)')
        for i, j in healthy2_check_config['post_json'].items():
            if j:
                post_dict[i] = j
        healthy2_check_dict = healthy2_check_in(token, user_info["customerId"], post_dict)
        
        check_dict_list.append(healthy2_check_dict)
    else:
        log.info('当前并未配置健康打卡方式,暂不进行打卡操作')
    
    # 校内打卡
    campus_check_config = user.get('campus_checkin', {})
    if not campus_check_config.get('enable'):
        log.info('当前并未开启校内打卡,暂不进行打卡操作')
    else:
        # 获取校内打卡ID
        custom_type_id = user_info.get('customerAppTypeId', get_customer_type_id(token))
        if custom_type_id:
            id_list = get_id_list_v2(token, custom_type_id)
        else:
            id_list = get_id_list_v1(token)
        
        if not id_list:
            log.warning('当前未获取到校内打卡ID,请尝试重新运行,如仍未获取到,请反馈')
            return check_dict_list
        for index, i in enumerate(id_list):
            start_end = f'{i["templateid"]} ({i.get("startTime", "")}-{i.get("endTime", "")})'
            log.info(f"{start_end:-^40}")
            
            # 获取校内打卡参数
            campus_dict = get_campus_check_post(
                template_id=i['templateid'],
                custom_rule_id=i['id'],
                stu_num=user_info['stuNo'],
                token=token
            )
            # 合并配置文件的打卡信息
            merge_post_json(campus_dict, campus_check_config['post_json'])
            
            # 校内打卡
            campus_check_dict = campus_check_in(user['phone'], token, campus_dict, i['id'])
            check_dict_list.append(campus_check_dict)
            log.info("-" * 40)
    
    # 粮票收集
    if user.get('ykt_score'):
        ykt_check_in(token)
        get_all_score(token)
        task_list = get_task_list(token)
        for task in task_list:
            if task['name'] == '校园头条':
                if not task['finished']:
                    article_id = get_article_id(token)
                    for _ in range(8):
                        time.sleep(1)
                        get_article_score(token, article_id)
                else:
                    log.info("校园头条任务已完成")
            get_all_score(token)
            if task['name'] == '查看课表':
                if not task['finished']:
                    get_class_score(token)
                else:
                    log.info("查看课表任务已完成")
        # 获取活跃奖励
        get_active_score(token, get_score_list(token)['active'][0])
        
        # 获取其他奖励
        get_all_score(token)
        
    return check_dict_list
コード例 #2
0
def check_in(user):
    check_dict_list = []

    # 登录获取token用于打卡
    token = get_token(user['phone'], user['password'], user['device_id'])

    if not token:
        errmsg = f"{user['phone'][:4]},获取token失败,打卡失败"
        log.warning(errmsg)
        check_dict_list.append({"status": 0, "errmsg": errmsg})
        return check_dict_list

    # 获取个人信息
    user_info = get_user_info(token)
    if not user_info:
        errmsg = f"{user['phone'][:4]},获取个人信息失败,打卡失败"
        log.warning(errmsg)
        check_dict_list.append({"status": 0, "errmsg": errmsg})
        return check_dict_list
    log.info(f'{user_info["username"][0]}-{user_info["school"]},获取个人信息成功')

    healthy1_check_config = user['healthy_checkin']['one_check']
    healthy2_check_config = user['healthy_checkin']['two_check']
    if healthy1_check_config['enable']:
        # 第一类健康打卡

        # 获取第一类健康打卡的参数
        post_dict = get_healthy1_check_post_json(token)

        # 合并配置文件的打卡信息
        merge_post_json(post_dict, healthy1_check_config['post_json'])

        healthy1_check_dict = healthy1_check_in(token, user['phone'],
                                                post_dict)
        check_dict_list.append(healthy1_check_dict)
    elif healthy2_check_config['enable']:
        # 第二类健康打卡

        # 获取第二类健康打卡参数
        post_dict = get_healthy2_check_posh_json(token)

        # 合并配置文件的打卡信息
        if not healthy2_check_config['post_json'][
                'latitude'] and not healthy2_check_config['post_json'][
                    'longitude']:
            post_dict['latitude'] = ""
            post_dict['longitude'] = ""
            log.info('当前打卡未设置经纬度,后台会将此次打卡计为手动打卡(学校没做要求可不管)')
        for i, j in healthy2_check_config['post_json'].items():
            if j:
                post_dict[i] = j
        healthy2_check_dict = healthy2_check_in(token, user_info["customerId"],
                                                post_dict)

        check_dict_list.append(healthy2_check_dict)
    else:
        log.info('当前并未配置健康打卡方式,暂不进行打卡操作')

    # 校内打卡
    campus_check_config = user['campus_checkin']
    if not campus_check_config['enable']:
        log.info('当前并未开启校内打卡,暂不进行打卡操作')
    else:
        # 获取校内打卡ID
        custom_type_id = user_info.get('customerAppTypeId',
                                       get_customer_type_id(token))
        if custom_type_id:
            id_list = get_id_list_v2(token, custom_type_id)
        else:
            id_list = get_id_list_v1(token)

        if not id_list:
            log.warning('当前未获取到校内打卡ID,请尝试重新运行,如仍未获取到,请反馈')
            return check_dict_list
        for index, i in enumerate(id_list):
            start_end = f'{i["templateid"]} ({i.get("startTime", "")}-{i.get("endTime", "")})'
            log.info(f"{start_end:-^40}")

            # 获取校内打卡参数
            campus_dict = get_campus_check_post(template_id=i['templateid'],
                                                custom_rule_id=i['id'],
                                                stu_num=user_info['stuNo'],
                                                token=token)
            # 合并配置文件的打卡信息
            merge_post_json(campus_dict, campus_check_config['post_json'])

            # 校内打卡
            campus_check_dict = campus_check_in(user['phone'], token,
                                                campus_dict, i['id'])
            check_dict_list.append(campus_check_dict)
            log.info("-" * 40)
    return check_dict_list