Пример #1
0
    def download_latest_notices(self):
        uploader = Uploader()

        dirpath, filename = os.path.dirname(self.cache_path), os.path.basename(
            self.cache_path)
        uploader.download_file_in_folder(uploader.folder_online_files,
                                         filename,
                                         dirpath,
                                         try_compressed_version_first=True)
Пример #2
0
def has_buy_auto_updater_dlc(cfg: Config):
    retrtCfg = cfg.common.retry
    for idx in range(retrtCfg.max_retry_count):
        try:
            uploader = Uploader(lanzou_cookie)
            user_list_filepath = uploader.download_file_in_folder(uploader.folder_online_files, uploader.buy_auto_updater_users_filename, ".cached", show_log=False)
            buy_users = []
            with open(user_list_filepath, 'r', encoding='utf-8') as data_file:
                buy_users = json.load(data_file)

            if len(buy_users) == 0:
                # note: 如果读取失败或云盘该文件列表为空,则默认所有人都放行
                return True

            for account_cfg in cfg.account_configs:
                qq = uin2qq(account_cfg.account_info.uin)
                if qq in buy_users:
                    return True

            return False
        except Exception as e:
            logFunc = logger.debug
            if use_by_myself():
                logFunc = logger.error
            logFunc(f"第{idx + 1}次检查是否购买DLC时出错了,稍后重试", exc_info=e)
            time.sleep(retrtCfg.retry_wait_time)

    return True
Пример #3
0
def has_buy_auto_updater_dlc(cfg: Config):
    retrtCfg = cfg.common.retry
    for idx in range(retrtCfg.max_retry_count):
        try:
            uploader = Uploader(lanzou_cookie)
            has_no_users = True
            for remote_filename in [
                    uploader.buy_auto_updater_users_filename,
                    uploader.cs_buy_auto_updater_users_filename
            ]:
                try:
                    user_list_filepath = uploader.download_file_in_folder(
                        uploader.folder_online_files,
                        remote_filename,
                        ".cached",
                        show_log=False)
                except FileNotFoundError as e:
                    # 如果网盘没有这个文件,就跳过
                    continue

                buy_users = []
                with open(user_list_filepath, 'r',
                          encoding='utf-8') as data_file:
                    buy_users = json.load(data_file)

                if len(buy_users) != 0:
                    has_no_users = False

                for account_cfg in cfg.account_configs:
                    qq = uin2qq(account_cfg.account_info.uin)
                    if qq in buy_users:
                        return True

                logger.debug((
                    "DLC购买调试日志:\n"
                    f"remote_filename={remote_filename}\n"
                    f"账号列表={[uin2qq(account_cfg.account_info.uin) for account_cfg in cfg.account_configs]}\n"
                    f"用户列表={buy_users}\n"))

            if has_no_users:
                # note: 如果读取失败或云盘该文件列表为空,则默认所有人都放行
                return True

            return False
        except Exception as e:
            logFunc = logger.debug
            if use_by_myself():
                logFunc = logger.error
            logFunc(f"第{idx + 1}次检查是否购买DLC时出错了,稍后重试", exc_info=e)
            time.sleep(retrtCfg.retry_wait_time)

    return True
Пример #4
0
def get_user_buy_info(cfg: Config):
    retrtCfg = cfg.common.retry
    default_user_buy_info = BuyInfo()
    for idx in range(retrtCfg.max_retry_count):
        try:
            # 默认设置首个qq为购买信息
            default_user_buy_info.qq = uin2qq(
                cfg.account_configs[0].account_info.uin)

            uploader = Uploader(lanzou_cookie)
            buy_info_filepath = uploader.download_file_in_folder(
                uploader.folder_online_files,
                uploader.user_monthly_pay_info_filename,
                ".cached",
                show_log=False)
            buy_users = {}  # type: Dict[str, BuyInfo]
            with open(buy_info_filepath, 'r', encoding='utf-8') as data_file:
                raw_infos = json.load(data_file)
                for qq, raw_info in raw_infos.items():
                    info = BuyInfo().auto_update_config(raw_info)
                    buy_users[qq] = info
                    for game_qq in info.game_qqs:
                        buy_users[game_qq] = info

            if len(buy_users) == 0:
                # note: 如果读取失败或云盘该文件列表为空,则默认所有人都放行
                default_user_buy_info.expire_at = "2120-01-01 00:00:00"
                return default_user_buy_info

            user_buy_info = default_user_buy_info
            for account_cfg in cfg.account_configs:
                qq = uin2qq(account_cfg.account_info.uin)
                if qq in buy_users:
                    if time_less(user_buy_info.expire_at,
                                 buy_users[qq].expire_at):
                        # 若当前配置的账号中有多个账号都付费了,选择其中付费结束时间最晚的那个
                        user_buy_info = buy_users[qq]

            return user_buy_info
        except Exception as e:
            logFunc = logger.debug
            if use_by_myself():
                logFunc = logger.error
            logFunc(f"第{idx + 1}次检查是否付费时出错了,稍后重试", exc_info=e)
            time.sleep(retrtCfg.retry_wait_time)

    return default_user_buy_info
Пример #5
0
def _get_user_buy_info(cfg: Config):
    retrtCfg = cfg.common.retry
    default_user_buy_info = BuyInfo()
    for try_idx in range(retrtCfg.max_retry_count):
        try:
            # 默认设置首个qq为购买信息
            default_user_buy_info.qq = uin2qq(cfg.account_configs[0].account_info.uin)

            uploader = Uploader(lanzou_cookie)
            has_no_users = True

            remote_filenames = [uploader.user_monthly_pay_info_filename, uploader.cs_user_monthly_pay_info_filename]
            import copy
            # 单种渠道内选择付费结束时间最晚的,手动和卡密间则叠加
            user_buy_info_list = [copy.deepcopy(default_user_buy_info) for v in remote_filenames]
            for idx, remote_filename in enumerate(remote_filenames):
                user_buy_info = user_buy_info_list[idx]

                try:
                    buy_info_filepath = uploader.download_file_in_folder(uploader.folder_online_files, remote_filename, ".cached", show_log=False)
                except FileNotFoundError as e:
                    # 如果网盘没有这个文件,就跳过
                    continue

                buy_users = {}  # type: Dict[str, BuyInfo]
                with open(buy_info_filepath, 'r', encoding='utf-8') as data_file:
                    raw_infos = json.load(data_file)
                    for qq, raw_info in raw_infos.items():
                        info = BuyInfo().auto_update_config(raw_info)
                        buy_users[qq] = info
                        for game_qq in info.game_qqs:
                            buy_users[game_qq] = info

                if len(buy_users) != 0:
                    has_no_users = False

                for account_cfg in cfg.account_configs:
                    qq = uin2qq(account_cfg.account_info.uin)
                    if qq in buy_users:
                        if time_less(user_buy_info.expire_at, buy_users[qq].expire_at):
                            # 若当前配置的账号中有多个账号都付费了,选择其中付费结束时间最晚的那个
                            user_buy_info = buy_users[qq]

                user_buy_info_list[idx] = user_buy_info

            if has_no_users:
                # note: 如果读取失败或云盘该文件列表为空,则默认所有人都放行
                default_user_buy_info.expire_at = "2120-01-01 00:00:00"
                return default_user_buy_info

            merged_user_buy_info = copy.deepcopy(default_user_buy_info)
            for user_buy_info in user_buy_info_list:
                if user_buy_info.total_buy_month == 0:
                    continue

                if merged_user_buy_info.total_buy_month == 0:
                    merged_user_buy_info = copy.deepcopy(user_buy_info)
                else:
                    merged_user_buy_info.merge(user_buy_info)

            return merged_user_buy_info
        except Exception as e:
            logFunc = logger.debug
            if use_by_myself():
                logFunc = logger.error
            logFunc(f"第{try_idx + 1}次检查是否付费时出错了,稍后重试", exc_info=e)
            time.sleep(retrtCfg.retry_wait_time)

    return default_user_buy_info
Пример #6
0
    def check_and_download_chrome_ahead(self):
        """
        尝试预先下载解压缩chrome的driver和便携版
        主要用于处理多进程模式下,可能多个进程同时尝试该操作导致的问题
        :return:
        """
        logger.info("检查chrome相关内容是否ok")
        logger.info(
            color("bold_yellow") +
            f"如果自动下载失败,可能是网络问题,请根据提示下载的内容,自行去网盘下载该内容到utils目录下 https://fzls.lanzoui.com/s/djc-tools"
        )
        chrome_driver_exe_name = os.path.basename(
            self.chrome_driver_executable_path())
        zip_name = os.path.basename(self.chrome_binary_7z())
        chrome_root_directory = self.chrome_root_directory()

        logger.info("检查driver是否存在")
        if not os.path.isfile(self.chrome_driver_executable_path()):
            logger.info(
                color("bold_yellow") +
                f"未在小助手utils目录里发现 {chrome_driver_exe_name} ,将尝试从网盘下载")
            uploader = Uploader()
            uploader.download_file_in_folder(uploader.folder_djc_helper_tools,
                                             chrome_driver_exe_name,
                                             chrome_root_directory)

        options = Options()
        options.headless = True
        options.add_experimental_option("excludeSwitches", ["enable-logging"])
        if not self.cfg.force_use_portable_chrome:
            try:
                logger.info("检查系统自带的chrome是否可用")
                self.driver = webdriver.Chrome(
                    executable_path=self.chrome_driver_executable_path(),
                    options=options)
                self.driver.quit()
                return
            except:
                logger.info("走到这里说明系统自带的chrome不可用")
                pass
        else:
            logger.info("当前配置为强制使用便携版chrome")

        # 尝试从网盘下载合适版本的便携版chrome
        if not os.path.isfile(self.chrome_binary_7z()):
            logger.info(
                color("bold_yellow") +
                f"本地未发现便携版chrome的压缩包,尝试自动从网盘下载 {zip_name},需要下载大概80MB的压缩包,请耐心等候"
            )
            uploader = Uploader()
            uploader.download_file_in_folder(uploader.folder_djc_helper_tools,
                                             zip_name, chrome_root_directory)

        # 尝试解压
        if not os.path.isdir(self.chrome_binary_directory()):
            logger.info(f"自动解压便携版chrome到当前目录")
            decompress_dir_with_bandizip(
                self.chrome_binary_7z(),
                dst_parent_folder=chrome_root_directory)

        logger.info("检查便携版chrome是否有效")
        try:
            options.binary_location = self.chrome_binary_location()
            # you may need some other options
            options.add_argument('--no-sandbox')
            options.add_argument('--no-default-browser-check')
            options.add_argument('--no-first-run')
            self.driver = webdriver.Chrome(
                executable_path=self.chrome_driver_executable_path(),
                options=options)
            self.driver.quit()
            return
        except:
            pass

        # 走到这里,大概率是多线程并行下载导致文件出错了,尝试重新下载
        logger.info(color("bold_yellow") + "似乎chrome相关文件损坏了,尝试重新下载并解压")
        uploader = Uploader()
        uploader.download_file_in_folder(uploader.folder_djc_helper_tools,
                                         chrome_driver_exe_name,
                                         chrome_root_directory,
                                         cache_max_seconds=0)
        uploader.download_file_in_folder(uploader.folder_djc_helper_tools,
                                         zip_name,
                                         chrome_root_directory,
                                         cache_max_seconds=0)

        shutil.rmtree(self.chrome_binary_directory(), ignore_errors=True)
        decompress_dir_with_bandizip(self.chrome_binary_7z(),
                                     dst_parent_folder=chrome_root_directory)