Beispiel #1
0
    def Add_Execute_Permission(self, system: SYSTEM) -> bool:
        """
        Add_Execute_Permission -> bool
        为驱动程序添加执行权限

        :param system: 系统类
        :return: bool
        """
        command = system.Driver_Chmod+PATH().Driver_File
        if command != PATH().Driver_File:
            return os.system(command=command) == 0
        return True
Beispiel #2
0
    def Download(self, link: ParseResult) -> int:
        """
        Download(link: ParseResult) -> int
        驱动下载

        :param link: 驱动下载链接
        :return: int 文件大小, 默认单位B
        """
        suffix = os.path.basename(link.path)
        zip_file = os.path.join(PATH().Driver, suffix)
        shutil.rmtree(path=PATH().Driver)
        os.mkdir(PATH().Driver)
        temp = self.__Download(link=link, dst=zip_file)
        self.__Unzip(dst=zip_file)
        return temp
Beispiel #3
0
    def File(self) -> bool:
        """
        File -> bool
        驱动文件是否存在

        :return: bool
        """
        return os.path.exists(PATH().Driver_File)
Beispiel #4
0
    def Dir(self) -> bool:
        """
        Dir -> bool
        驱动目录是否存在

        :return: bool
        """
        return os.path.exists(PATH().Driver)
Beispiel #5
0
    def Dir(self) -> bool:
        """
        Dir -> bool
        是否存在数据库目录

        :return: bool
        """
        return os.path.exists(PATH().DB)
Beispiel #6
0
    def __init__(self):
        """
        DB_MANAGE()
        初始化时自动检查数据库信息

        """
        DB_CHECK().Check_Dir()
        self.__connect = sqlite3.connect(PATH().DB_File)
        self.__cursor = self.__connect.cursor()
        self.__Check_Table()
Beispiel #7
0
    def Check_Dir(self) -> None:
        """
        Check_Dir() -> None
        检查数据库目录是否存在,如不存在则自动创建

        :return: None
        """
        if not self.Dir:
            print(f"检测到数据库目录未创建\n" f"自动创建中")
            os.mkdir(PATH().DB)
            print(f"数据库目录为{PATH().DB}")
Beispiel #8
0
    def Open(self) -> None:
        """
        Open() -> None
        打开

        :return: None
        """
        if not hasattr(self,
                       self.__self + '__mitmdump') or self.__mitmdump.poll():
            self.__mitmdump = subprocess.Popen('mitmdump -q -p 8080 -s ' +
                                               PATH().Intercept)
Beispiel #9
0
    def Open(self) -> None:
        """
        Open() -> None
        打开

        :return: None
        """
        if not hasattr(self, self.__self+'__mitmdump') or self.__mitmdump.poll():
            self.__mitmdump = subprocess.Popen(
                ['mitmdump', '-q', '-p', '8080', '-s', PATH().Intercept]
            )
Beispiel #10
0
    def Version(self) -> str:
        """
        Version -> str
        驱动支持谷歌浏览器版本号

        :return: str
        """
        cmd = PATH().Driver_File + ' --version'
        version = os.popen(cmd=cmd).readline()
        version = version.strip().split()
        return version[1]
    def __Baidu_AI(cls) -> None:
        """
        __Baidu_AI() -> None
        百度AI选项(默认:False)

        Returns: None

        """
        baidu_ai = input('是否使用百度AI(y/N):').strip()
        if baidu_ai in ['y', 'Y']:
            OPTIONS().Baidu_AI = True
            BAIDU_AI_MANAGE.Verify()
            with open(PATH().Baidu_AI_On, 'w', encoding='utf-8') as f:
                f.write("1")
                f.close()
        else:
            OPTIONS().Baidu_AI = False
            with open(PATH().Baidu_AI_On, 'w', encoding='utf-8') as f:
                f.write("0")
                f.close()
Beispiel #12
0
    def QR_Driver(self) -> WebDriver:
        """
        Task_Driver -> WebDriver
        二维码浏览器,根据默认配置文件生成

        :return: WebDriver
        """
        if not self.__instances.get('QR'):
            self.__instances['QR'] = Chrome(executable_path=PATH().Driver_File)
            self.__instances['QR'].set_window_size(width=50, height=350)
        return self.__instances['QR']
Beispiel #13
0
    def Task_Driver(self) -> WebDriver:
        """
        Task_Driver -> WebDriver
        任务浏览器,根据配置文件生成

        :return: WebDriver
        """
        if not self.__instances.get('Task'):
            self.__instances['Task'] = Chrome(
                desired_capabilities=self.__config,
                executable_path=PATH().Driver_File)
        return self.__instances['Task']
Beispiel #14
0
    def __Unzip(self, dst: str) -> bool:
        """
        __Unzip(dst: str) -> bool
        解压zip文件

        :param dst: 解压路径
        :return:
        """
        if zipfile.is_zipfile(dst):
            files = zipfile.ZipFile(dst)
            if not files.testzip():
                files.extractall(path=PATH().Driver)
                return True
            return False
Beispiel #15
0
    def __Check_Dir(cls) -> bool:
        """
        Check_Dir() -> None
        检测驱动目录是否存在,如不存在则自动创建

        :return: bool
        """
        if not DRIVER_CHECK().Dir:
            print(f"检测到驱动目录未创建\n"
                  f"自动创建中")
            os.mkdir(PATH().Driver)
            print(f"驱动目录为{PATH().Driver}")
            return False
        return True
Beispiel #16
0
 def __init__(self):
     """初始化驱动配置文件"""
     self.__config = {
         'browserName': 'chrome',
         # network日志相关
         'loggingPrefs': {
             'browser': 'ALL',
             'driver': 'ALL',
             'performance': 'ALL'
         },
         'goog:chromeOptions': {
             'prefs': {
                 # 默认下载目录
                 "download.default_directory": PATH().Temp,
                 # 自动下载
                 "download.prompt_for_download": False,
                 # 无图模式
                 "profile.managed_default_content_settings.images": 2
             },
             'excludeSwitches': [
                 # 不显示日志
                 'enable-logging',
                 # 规避检测
                 'enable-automation'
             ],
             'args': [
                 # 浏览器标识
                 '--user-agent=' + USER_AGENT().User_Agent,
                 # 本地代理
                 '--proxy-server=127.0.0.1:8080',
                 # 忽略证书问题
                 '--ignore-certificate-errors'
             ],
             'perfLoggingPrefs': {
                 # 开启network日志
                 'enableNetwork': True
             },
             'w3c':
             False
         }
     }
     self.__Check_Options()
Beispiel #17
0
    def __Answer(self, res: Dict) -> List[Dict]:
        """
        __Answer(res: Dict) -> List[Dict]
        由于专项答题没有答案,判题是在云端,所以需要分析答案

        :param res: 包含提示的题目
        :return: List[Dict]
        """
        res_type = res['questionDisplay']
        temp = []
        options = re.findall(r"<font color=\"red\">.*?</font>",
                             res['questionDesc'])
        for index, value in enumerate(options):
            options[index] = value.split('>')[1].split('<')[0]
        if res_type in (1, 2):
            for option in options:
                for answer in res['answers']:
                    if option in answer['content'] or answer[
                            'content'] in option:
                        tp = {
                            'answerId': answer['answerId'],
                            'value': answer['label']
                        }
                        if tp not in temp:
                            temp.append(tp)
            if not temp:
                for answer in res['answers']:
                    if answer['content'] in res['questionDesc']:
                        tp = {
                            'answerId': answer['answerId'],
                            'value': answer['label']
                        }
                        if tp not in temp:
                            temp.append(tp)
        elif res_type == 4:
            with open(PATH().Baidu_AI_On, 'r', encoding='utf-8') as f:
                on = f.read()
                f.close()
            if on == '1':
                if res['questionDesc'] == '请观看视频':
                    body = res['body']
                    value = BAIDU_AI_MANAGE.Tools().Answer(
                        video_link=res['videoUrl'])
                    print('检测到视频题目,由于专项答题答案匹配目前还未完善,所以需要手动填入答案')
                    print(f"题目部分:{body[body.index('()')-len(value):]}")
                    print(f"答案为:{value}")
                    print("请从答案中提取个数与()个数一致的答案,以空格分隔,注意顺序")
                    while True:
                        daan = input(":").strip().split()
                        check = [ck for ck in daan if ck in value]
                        if len(check) != len(daan) or not daan:
                            print("输入非答案,重新输入!")
                            continue
                        break
                    for index, answer in enumerate(res['answers']):
                        temp.append({
                            'answerId': answer['answerId'],
                            'value': daan[index]
                        })
            else:
                num = res['body'].count('()')
                if num == 1:
                    tp = ''
                    for option in options:
                        tp += option
                    temp.append({
                        'answerId': res['answers'][0]['answerId'],
                        'value': tp
                    })
                else:
                    for index, option in enumerate(options):
                        temp.append({
                            'answerId':
                            res['answers'][index]['answerId'],
                            'value':
                            option
                        })
        return temp