Пример #1
0
    def get_cookie_from_network(self):
        print("正在打开二维码登陆界面,请稍后")
        self.driver.get("https://pc.xuexi.cn/points/login.html")
        try:
            remover = WebDriverWait(self.driver, 30, 0.2).until(
                lambda driver: driver.find_element_by_class_name("redflagbox"))
        except exceptions.TimeoutException:
            print("网络缓慢,请重试")
        else:
            self.driver.execute_script('arguments[0].remove()', remover)
        try:
            remover = WebDriverWait(
                self.driver, 30,
                0.2).until(lambda driver: driver.find_element_by_class_name(
                    "layout-header"))
        except exceptions.TimeoutException:
            print("当前网络缓慢...")
        else:
            self.driver.execute_script('arguments[0].remove()', remover)
        try:
            remover = WebDriverWait(
                self.driver, 30,
                0.2).until(lambda driver: driver.find_element_by_class_name(
                    "layout-footer"))
        except exceptions.TimeoutException:
            print("当前网络缓慢...")
        else:
            self.driver.execute_script('arguments[0].remove()', remover)
            self.driver.execute_script(
                'window.scrollTo(document.body.scrollWidth/2 - 200 , 0)')

        try:
            # 取出iframe中二维码,并发往钉钉
            if cfg["addition"]["SendLoginQRcode"] == "1":
                print("二维码将发往钉钉机器人...\n" + "=" * 60)
                self.toDingDing()
        except KeyError as e:
            print("未检测到SendLoginQRcode配置,请手动扫描二维码登陆...")

        try:
            # WebDriverWait(self.driver, 270).until(EC.title_is(u"我的学 xi "))
            WebDriverWait(self.driver, 270).until(title_of_login())
            cookies = self.get_cookies()

            user.save_cookies(cookies)

            return cookies
        except Exception as e:
            self.quit()
            print("扫描二维码超时... 错误信息:" + str(e))
            if str(e).find("check_hostname") > -1 and str(e).find(
                    "server_hostname") > -1:
                print("针对“check_hostname requires server_hostname”问题:")
                print("您的网络连接存在问题,请检查您与xuexi.cn的网络连接并关闭“某些”软件")
            input("按回车键退出程序. ")
            exit()
Пример #2
0
def add_user(chat_id=None):
    get_argv()
    gl.pushprint("请登录(登录方式请仔细阅读文档,如果觉得这是让你下载,就是你没仔细读文档):", chat_id=chat_id)
    driver_login = Mydriver()
    cookies = driver_login.login(chat_id)
    driver_login.quit()
    if not cookies:
        gl.pushprint("登录超时。", chat_id=chat_id)
        return
    user.save_cookies(cookies)
    uid = user.get_userId(cookies)
    user_fullname = user.get_fullname(uid)
    user.update_last_user(uid)
    gl.pushprint(user_fullname + "登录成功", chat_id=chat_id)
Пример #3
0
    def get_cookie_from_network(self):
        print("正在打开二维码登陆界面,请稍后")
        self.driver.get("https://pc.xuexi.cn/points/login.html")
        try:
            remover = WebDriverWait(self.driver, 30, 0.2).until(
                lambda driver: driver.find_element_by_class_name("redflagbox"))
        except exceptions.TimeoutException:
            print("网络缓慢,请重试")
        else:
            self.driver.execute_script('arguments[0].remove()', remover)
        try:
            remover = WebDriverWait(
                self.driver, 30,
                0.2).until(lambda driver: driver.find_element_by_class_name(
                    "layout-header"))
        except exceptions.TimeoutException:
            print("当前网络缓慢...")
        else:
            self.driver.execute_script('arguments[0].remove()', remover)
        try:
            remover = WebDriverWait(
                self.driver, 30,
                0.2).until(lambda driver: driver.find_element_by_class_name(
                    "layout-footer"))
        except exceptions.TimeoutException:
            print("当前网络缓慢...")
        else:
            self.driver.execute_script('arguments[0].remove()', remover)
            self.driver.execute_script(
                'window.scrollTo(document.body.scrollWidth/2 - 200 , 0)')
        try:
            # WebDriverWait(self.driver, 270).until(EC.title_is(u"我的学习"))
            WebDriverWait(self.driver, 270).until(title_of_login())
            cookies = self.get_cookies()

            user.save_cookies(cookies)

            return cookies
        except Exception as e:
            self.quit()
            input("扫描二维码超时... 按回车键退出程序. 错误信息:" + str(e))
            exit()
Пример #4
0
def start_learn(uid, name):
    nohead, lock, stime = get_argv()
    print("是否无头模式:{0} {1}".format(nohead, os.getenv('Nohead')))
    cookies = user.get_cookie(uid)
    if nohead == True:
        TechXueXi_mode = "3"
    else:
        try:
            if cfg["base"]["ModeType"]:
                print("默认选择模式:" + str(cfg["base"]["ModeType"]) + "\n" +
                      "=" * 60)
                TechXueXi_mode = str(cfg["base"]["ModeType"])
        except Exception as e:
            TechXueXi_mode = "3"
    if not name:
        user_fullname = user.get_fullname(uid)
    else:
        user_fullname = uid + "_" + name
    if not cookies or TechXueXi_mode == "0":
        msg = ""
        if name == "新用户":
            msg = "需要增加新用户,请扫码登录,否则请无视"
        else:
            msg = user_fullname + "登录信息失效,请重新扫码"
        print(msg)
        gl.pushprint(msg)
        driver_login = Mydriver()
        cookies = driver_login.login()
        driver_login.quit()
        if not cookies:
            print("登录超时")
            return
        user.save_cookies(cookies)
        uid = user.get_userId(cookies)
        user_fullname = user.get_fullname(uid)
        user.update_last_user(uid)
    output = "\n用户:" + user_fullname + "登录正常,开始学习...\n"

    article_index = user.get_article_index(uid)
    video_index = 1  # user.get_video_index(uid)

    total, scores = show_score(cookies)
    gl.pushprint(output)
    if TechXueXi_mode in ["1", "3"]:

        article_thread = threads.MyThread("文章学 xi ",
                                          article,
                                          uid,
                                          cookies,
                                          article_index,
                                          scores,
                                          lock=lock)
        video_thread = threads.MyThread("视频学 xi ",
                                        video,
                                        uid,
                                        cookies,
                                        video_index,
                                        scores,
                                        lock=lock)
        article_thread.start()
        video_thread.start()
        article_thread.join()
        video_thread.join()
    if TechXueXi_mode in ["2", "3"]:
        driver_default = Mydriver()
        print('开始每日答题……')
        daily(cookies, scores, driver_default=driver_default)
        if TechXueXi_mode in ["2", "3"]:
            print('开始每周答题……')
            weekly(cookies, scores, driver_default=driver_default)
            if nohead != True:
                print('开始专项答题……')
                zhuanxiang(cookies, scores, driver_default=driver_default)
        try:
            driver_default.quit()
        except Exception as e:
            gl.pushprint('driver_default 在 main 退出时出了一点小问题...')
    if TechXueXi_mode == "4":
        user.select_user()
    if TechXueXi_mode == "5":
        user.refresh_all_cookies(display_score=True)
    if TechXueXi_mode == "6":
        user.refresh_all_cookies(live_time=11.90)

    seconds_used = int(time.time() - start_time)
    print("总计用时 " + str(math.floor(seconds_used / 60)) + " 分 " +
          str(seconds_used % 60) + " 秒")
    show_scorePush(cookies)
    try:
        user.shutdown(stime)
    except Exception as e:
        pass
Пример #5
0
    print("=" * 60, '''\nTechXueXi 现支持以下模式(答题时请值守电脑旁处理少部分不正常的题目):''')
    print(cfg['base']['ModeText'] + '\n' +
          "=" * 60)  # 模式提示文字请在 ./config/main.ini 处修改。
    # TechXueXi_mode = input("请选择模式(输入对应数字)并回车: ")
    # 懒人之最版
    TechXueXi_mode = cfg['base']['Mode']

    info_shread = threads.MyThread("获取更新信息...", version.up_info)
    info_shread.start()
    #  1 创建用户标记,区分多个用户历史纪录
    uid = user.get_default_userId()
    if not cookies:
        print("未找到有效登录信息,需要登录")
        driver_login = Mydriver(nohead=False)
        cookies = driver_login.login()
        user.save_cookies(cookies)
        uid = user.get_userId(cookies)
        user_fullname = user.get_fullname(uid)
        user.update_last_user(uid)
        try:
            driver_login.quit()
        except:
            print("wtf:退出webdriver失败?")
            pass
    article_index = user.get_article_index(uid)
    video_index = user.get_video_index(uid)

    total, scores = show_score(cookies)
    nohead, lock, stime = get_argv()

    article_thread = threads.MyThread("文章学习",
Пример #6
0
def start_learn(uid, name):
    #  0 读取版本信息
    start_time = time.time()
    nohead, lock, stime, Single = get_argv()
    print("是否无头模式:{0} {1}".format(nohead, os.getenv('Nohead')))
    cookies = user.get_cookie(uid)
    if nohead == True:
        TechXueXi_mode = "3"
    else:
        TechXueXi_mode = str(cfg_get("base.ModeType", 3))
        print("当前选择模式:" + TechXueXi_mode + "\n" + "=" * 60)

    if not name:
        user_fullname = user.get_fullname(uid)
        name = user_fullname.split('_', 1)[1]
    else:
        user_fullname = uid + "_" + name

    if not cookies or TechXueXi_mode == "0":
        msg = ""
        if name == "新用户":
            msg = "需要增加新用户,请扫码登录,否则请无视"
        else:
            msg = name + " 登录信息失效,请重新扫码"
        # print(msg)
        gl.pushprint(msg, chat_id=uid)
        if gl.pushmode == "6":
            gl.pushprint("web模式跳过自动获取二维码,请手动点击添加按钮", chat_id=uid)
            print(color.red("【#️⃣】 若直接退出请运行:webserverListener.py"))
            return
        driver_login = Mydriver()
        cookies = driver_login.login()
        driver_login.quit()
        if not cookies:
            print("登录超时")
            return
        user.save_cookies(cookies)
        uid = user.get_userId(cookies)
        user_fullname = user.get_fullname(uid)
        name = user_fullname.split('_', 1)[1]
        user.update_last_user(uid)
    output = name + " 登录正常,开始学习...\n"

    article_index = user.get_article_index(uid)
    video_index = 1  # user.get_video_index(uid)

    total, scores = show_score(cookies)
    gl.pushprint(output, chat_id=uid)
    if TechXueXi_mode in ["1", "3"]:

        article_thread = threads.MyThread("文章学 xi ",
                                          article,
                                          uid,
                                          cookies,
                                          article_index,
                                          scores,
                                          lock=lock)
        video_thread = threads.MyThread("视频学 xi ",
                                        video,
                                        uid,
                                        cookies,
                                        video_index,
                                        scores,
                                        lock=lock)
        article_thread.start()
        video_thread.start()
        article_thread.join()
        video_thread.join()
    if TechXueXi_mode in ["2", "3"]:
        print('开始每日答题……')
        daily(cookies, scores)
        print('开始每周答题……')
        weekly(cookies, scores)
        if nohead != True or gl.zhuanxiang == True:
            print('开始专项答题……')
            zhuanxiang(cookies, scores)

    if TechXueXi_mode == "4":
        user.select_user()
    if TechXueXi_mode == "5":
        user.refresh_all_cookies(display_score=True)
    if TechXueXi_mode == "6":
        user.refresh_all_cookies(live_time=11.90)

    seconds_used = int(time.time() - start_time)
    gl.pushprint(name + " 总计用时 " + str(math.floor(seconds_used / 60)) + " 分 " +
                 str(seconds_used % 60) + " 秒",
                 chat_id=uid)
    show_scorePush(cookies, chat_id=uid)
    try:
        user.shutdown(stime)
    except Exception as e:
        pass
Пример #7
0
    def get_cookie_from_network(self, chat_id=None):
        print("正在打开二维码登陆界面,请稍后")
        self.web_log('正在打开二维码登陆界面,请稍后')
        self.driver.get("https://pc.xuexi.cn/points/login.html")
        try:
            remover = WebDriverWait(self.driver, 30, 0.2).until(
                lambda driver: driver.find_element_by_class_name("redflagbox"))
        except exceptions.TimeoutException:
            print("网络缓慢,请重试")
        else:
            self.driver.execute_script('arguments[0].remove()', remover)
        try:
            remover = WebDriverWait(
                self.driver, 30,
                0.2).until(lambda driver: driver.find_element_by_class_name(
                    "layout-header"))
        except exceptions.TimeoutException:
            print("当前网络缓慢...")
        else:
            self.driver.execute_script('arguments[0].remove()', remover)
        try:
            remover = WebDriverWait(
                self.driver, 30,
                0.2).until(lambda driver: driver.find_element_by_class_name(
                    "layout-footer"))
        except exceptions.TimeoutException:
            print("当前网络缓慢...")
        else:
            self.driver.execute_script('arguments[0].remove()', remover)
            #修改了适配新版本的二维码的滚动位置
            self.driver.execute_script(
                'window.scrollTo(document.body.scrollWidth/2 - 200 , 400)')
        qrurl = ''
        qcbase64 = ''
        # 取出iframe中二维码,并发往钉钉
        if gl.nohead == True or cfg_get("addition.SendLoginQRcode", 0) == 1:
            print("二维码将发往机器人...\n" + "=" * 60)
            qrurl, qcbase64 = self.sendmsg(chat_id)

        # 扫码登录后删除二维码和登录链接 准备
        web_qr_url = web_db.session.query(WebQrUrl).filter_by(
            url=qcbase64).first()
        web_msg = web_db.session.query(WebMessage).filter_by(
            text=qrurl).first()

        # print(' ----------------------------------------------------------------')
        # print(web_qr_url)
        # print(' ----------------------------------------------------------------')
        # print(web_msg)
        # print(web_db.session.query(WebMessage).all())

        # try:
        #     # 取出iframe中二维码,并发往方糖,拿到的base64没办法直接发钉钉,所以发方糖
        #     if  gl.nohead==True or cfg["addition"]["SendLoginQRcode"] == 1 :
        #         print("二维码将发往方糖机器人...\n" + "=" * 60)
        #         self.toFangTang()
        # except Exception as e:
        #     print("未检测到SendLoginQRcode配置,请手动扫描二维码登陆..."+e)

        try:
            # 获取二维码图片  # 这一块等待测试完毕再加入代码
            # self.driver.switch_to.frame("ddlogin-iframe")
            # source = self.driver.page_source
            # picc = re.search(
            #     "(data:image/png;base64,)(.*)(\"></div><div data-v-be4de7b6)", source).group(2)
            # pic = base64.b64decode(picc)
            # 微信发送图片到手机,以便扫码(此配置项暂未应用至代码。结合 default_template.conf 修改)
            # wx = WeChat()
            # media_id = wx.get_media_url(pic)
            # wx.send_image(media_id)

            # WebDriverWait(self.driver, 270).until(EC.title_is(u"我的学习"))
            WebDriverWait(self.driver, 270).until(title_of_login())
            cookies = self.get_cookies()
            user.save_cookies(cookies)
            # 扫码登录后删除二维码和登录链接
            # print('扫码登录后删除二维码和登录链接 {} - {}'.format(web_msg, web_qr_url))
            self.web_log('扫码登录后删除二维码和登录链接')
            web_qr_url and web_db.session.delete(web_qr_url)
            web_msg and web_db.session.delete(web_msg)
            web_db.session.commit()
            return cookies

        except Exception as e:
            print("扫描二维码超时... 错误信息:" + str(e))
            self.web_log("扫描二维码超时... 错误信息:" + str(e))
            if (gl.islooplogin == True):
                print("循环模式开启,即将重新获取二维码")
                self.web_log("循环模式开启,即将重新获取二维码")
                time.sleep(3)
                return self.get_cookie_from_network()
            self.quit()

            if str(e).find("check_hostname") > -1 and str(e).find(
                    "server_hostname") > -1:
                print("针对“check_hostname requires server_hostname”问题:")
                print("您的网络连接存在问题,请检查您与xuexi.cn的网络连接并关闭“某些”软件")
                self.web_log("针对“check_hostname requires server_hostname”问题:")
                self.web_log("您的网络连接存在问题,请检查您与xuexi.cn的网络连接并关闭“某些”软件")
            auto.prompt("按回车键退出程序. ")
            exit()
Пример #8
0
 def get_cookie_from_network(self):
     print("正在打开二维码登陆界面,请稍后")
     self.driver.get("https://pc.xuexi.cn/points/login.html")
     try:
         remover = WebDriverWait(self.driver, 30, 0.2).until(
             lambda driver: driver.find_element_by_class_name("redflagbox"))
     except exceptions.TimeoutException:
         print("网络缓慢,请重试")
     else:
         self.driver.execute_script('arguments[0].remove()', remover)
     try:
         remover = WebDriverWait(
             self.driver, 30,
             0.2).until(lambda driver: driver.find_element_by_class_name(
                 "layout-header"))
     except exceptions.TimeoutException:
         print("当前网络缓慢...")
     else:
         self.driver.execute_script('arguments[0].remove()', remover)
     try:
         remover = WebDriverWait(
             self.driver, 30,
             0.2).until(lambda driver: driver.find_element_by_class_name(
                 "layout-footer"))
     except exceptions.TimeoutException:
         print("当前网络缓慢...")
     else:
         self.driver.execute_script('arguments[0].remove()', remover)
         self.driver.execute_script(
             'window.scrollTo(document.body.scrollWidth/2 - 200 , 0)')
     try:
         # WebDriverWait(self.driver, 270).until(EC.title_is(u"我的学习"))
         # 等待加载登录页面二维码
         WebDriverWait(self.driver, 270).until(title_of_login())
         time.sleep(2)
         self.driver.save_screenshot('qr.png')
         print("已截图")
         reader = zxing.BarCodeReader()
         barcode = reader.decode('qr.png')
         print(barcode.parsed)
         qr = qrcode.QRCode(
             version=2,
             error_correction=qrcode.constants.ERROR_CORRECT_L,
             box_size=25,
             border=6,
         )
         # 二维码内容
         data = barcode.parsed
         qr.add_data(data=data)
         qr.print_ascii()
         print("已识别二维码,请扫码或者复制上面链接自己生成二维码扫描")
         if (cfg.has_option('addition', 'SendLoginQRcode')
                 and cfg['addition']['SendLoginQRcode'] == '1'
                 and cfg.has_option('addition', 'WXPUSH')
                 and cfg.has_option('addition', 'WXPUSH_UID')):
             wxpush = cfg['addition']['WXPUSH']
             wxpush_uid = cfg['addition']['WXPUSH_UID']
             qr.make(fit=True)
             img = qr.make_image()
             img_buffer = BytesIO()
             img.save(img_buffer, 'png')
             res = img_buffer.getvalue()
             img_buffer.close()
             qr_img = base64.b64encode(res)
             # print(qr_img)
             if (len(wxpush_uid) > 0 and len(wxpush) > 0):
                 wxpush_data = {
                     "appToken":
                     wxpush,
                     "content":
                     "<h3>截图后扫码!</h3><br/><img src=\"data:image/png;base64,{0}\"/>"
                     .format(qr_img.decode('UTF-8')),
                     "summary":
                     "学习APP扫码登录",
                     "contentType":
                     2,
                     "uids": [wxpush_uid],
                 }
                 r = requests.post(
                     'http://wxpusher.zjiecode.com/api/send/message',
                     data=json.dumps(wxpush_data),
                     headers={'Content-Type': 'application/json'})
                 print("已发送:" + r.text)
             else:
                 print("请配置WXPUSH,https://wxpusher.zjiecode.com/docs/#/")
         WebDriverWait(self.driver, 270).until(title_of_loggedin())
         cookies = self.get_cookies()
         user.save_cookies(cookies)
         return cookies
     except Exception as e:
         self.quit()
         print("扫描二维码超时... 按回车键退出程序. 错误信息:" + str(e))
         # input("扫描二维码超时... 按回车键退出程序. 错误信息:" + str(e))
         exit()