def auto_send_cards(cfg): if not has_any_account_in_normal_run(cfg): return _show_head_line("运行完毕自动赠送卡片") target_qqs = cfg.common.auto_send_card_target_qqs if len(target_qqs) == 0: logger.warning("未定义自动赠送卡片的对象QQ数组,将跳过本阶段") return # 统计各账号卡片数目 logger.info("拉取各账号的卡片数据中,请耐心等待...") qq_to_card_name_to_counts = {} qq_to_prize_counts = {} qq_to_djcHelper = {} for _idx, account_config in enumerate(cfg.account_configs): idx = _idx + 1 if not account_config.is_enabled(): # 未启用的账户的账户不走该流程 continue djcHelper = DjcHelper(account_config, cfg.common) djcHelper.check_skey_expired() djcHelper.get_bind_role_list(print_warning=False) lr = djcHelper.fetch_pskey() if lr is None: continue qq = uin2qq(lr.uin) qa = QzoneActivity(djcHelper, lr) qq_to_card_name_to_counts[qq] = qa.get_card_counts() qq_to_prize_counts[qq] = qa.get_prize_counts() qq_to_djcHelper[qq] = djcHelper logger.info("{}/{} 账号 {:} 的数据拉取完毕".format( idx, len(cfg.account_configs), padLeftRight(account_config.name, 12))) # 赠送卡片 for target_qq in target_qqs: if target_qq in qq_to_djcHelper: left_times = qq_to_djcHelper[ target_qq].ark_lottery_query_left_times(target_qq) logger.warning( color("fg_bold_green") + "账号 {}({}) 今日仍可被赠送 {} 次卡片".format( qq_to_djcHelper[target_qq].cfg.name, target_qq, left_times) ) # 最多赠送目标账号今日仍可接收的卡片数 for i in range(left_times): send_card(target_qq, qq_to_card_name_to_counts, qq_to_prize_counts, qq_to_djcHelper) # 赠送卡片完毕后尝试抽奖 djcHelper = qq_to_djcHelper[target_qq] lr = djcHelper.fetch_pskey() if lr is not None: qa = QzoneActivity(djcHelper, lr) qa.try_lottery_using_cards(print_warning=False)
def auto_send_cards(cfg: Config): if not has_any_account_in_normal_run(cfg): return _show_head_line("运行完毕自动赠送卡片") target_qqs = cfg.common.auto_send_card_target_qqs if len(target_qqs) == 0: logger.warning("未定义自动赠送卡片的对象QQ数组,将跳过本阶段") return # 统计各账号卡片数目 logger.info("拉取各账号的卡片数据中,请耐心等待...") account_data = [] if cfg.common.enable_multiprocessing: logger.info(f"已开启多进程模式({cfg.get_pool_size()}),将并行拉取数据~") for data in get_pool().starmap(query_account_ark_lottery_info, [(_idx + 1, len(cfg.account_configs), account_config, cfg.common) for _idx, account_config in enumerate(cfg.account_configs) if account_config.is_enabled()]): account_data.append(data) else: for _idx, account_config in enumerate(cfg.account_configs): idx = _idx + 1 if not account_config.is_enabled(): # 未启用的账户的账户不走该流程 continue account_data.append(query_account_ark_lottery_info(idx, len(cfg.account_configs), account_config, cfg.common)) account_data = remove_none_from_list(account_data) qq_to_card_name_to_counts = {} qq_to_prize_counts = {} qq_to_djcHelper = {} for card_name_to_counts, prize_counts, djcHelper in account_data: qq = uin2qq(djcHelper.cfg.account_info.uin) qq_to_card_name_to_counts[qq] = card_name_to_counts qq_to_prize_counts[qq] = prize_counts qq_to_djcHelper[qq] = djcHelper # 赠送卡片 for idx, target_qq in enumerate(target_qqs): if target_qq in qq_to_djcHelper: left_times = qq_to_djcHelper[target_qq].ark_lottery_query_left_times(target_qq) name = qq_to_djcHelper[target_qq].cfg.name logger.warning(color("fg_bold_green") + f"第{idx + 1}/{len(target_qqs)}个赠送目标账号 {name}({target_qq}) 今日仍可被赠送 {left_times} 次卡片") # 最多赠送目标账号今日仍可接收的卡片数 for i in range(left_times): send_card(target_qq, qq_to_card_name_to_counts, qq_to_prize_counts, qq_to_djcHelper, target_qqs) # 赠送卡片完毕后尝试领取奖励和抽奖 djcHelper = qq_to_djcHelper[target_qq] lr = djcHelper.fetch_pskey() if lr is not None: logger.info("赠送完毕,尝试领取奖励和抽奖") qa = QzoneActivity(djcHelper, lr) qa.take_ark_lottery_awards(print_warning=False) qa.try_lottery_using_cards(print_warning=False)