Beispiel #1
0
def up_info():
    print(color.yellow("[*] 正在联网获取更新信息...(更新显示不会打断之前输入等操作)"))

    __INFO = "TechXueXi最新下载地址为 https://github.com/TechXueXi/TechXueXi"
    __SITE = "科技强国官方网站:https://techxuexi.js.org"

    # vercel_url = "https://techxuexi.vercel.app/Update.html"
    jsdelivery_url = "https://cdn.jsdelivr.net/gh/TechXueXi/TechXueXi@master/SourcePackages/pdlearn/version_info.json"
    try:
        native_info = get_native_json()
        native_version = native_info["techxuexi_version"]
        native_update_logs = native_info["techxuexi_update_log"]
        remote_json = requests.get(jsdelivery_url).content.decode("utf8")
        remote_info = json.loads(remote_json)
        remote_version = remote_info["techxuexi_version"]
        remote_update_logs = remote_info["techxuexi_update_log"]
        print(color.yellow("[*] " + __INFO))
        print(color.yellow("[*] 程序版本为:{}".format(native_version)))
        print(color.yellow("[*] 最新版本为:{}".format(remote_version)))
        if remote_version > native_version:  # 有新版本
            print(color.red("[*] 当前不是最新版本,建议更新"))
            print(color.red("[*] " + "=" * 60))
            print(color.red("[*] 更新提要:"))
            for log in remote_update_logs:
                if log["version"] > native_version:
                    print(color.red("[*] " + log["version"]))
                    print(color.red(log["info"]))
                else:
                    print(color.yellow("[*] " + __INFO))
                    print(color.yellow("[*] " + __SITE))
                    break
    except:
        print(color.yellow("[*] 版本信息网络错误"))
Beispiel #2
0
def up_info():
    print(color.yellow("[*] 正在联网获取更新信息...(更新显示不会打断之前输入等操作)"))

    __INFO = "TechXueXi最新下载地址为 https://github.com/TechXueXi/TechXueXi"
    __SITE = "科技强国官方网站:https://techxuexi.js.org"

    # vercel_url = "https://techxuexi.vercel.app/Update.html"
    jsdelivery_url = "https://cdn.jsdelivr.net/gh/TechXueXi/TechXueXi@master/SourcePackages/pdlearn/version_info.json"
    try:
        native_info = get_native_json()
        remote_json = requests.get(jsdelivery_url).content.decode("utf8")
        remote_info = json.loads(remote_json)
        print(remote_info["notice"])
    except:
        print(color.yellow("[*] 版本信息网络错误"))
    try:
        remote_least_version = int((str(remote_info["least_version"]))[1:])
        int_native_version = int((str(native_info["techxuexi_version"]))[1:])
        if int_native_version < remote_least_version:
            old_version_warning = remote_info["old_version_warning"]
            print(color.yellow("[*] 您的版本太低,程序不会继续运行。请升级:"))
            print(old_version_warning)
            while True:
                time.sleep(6000)
    except:
        print(color.yellow("[*] 查询本版本是否能继续使用,错误"))
    try:
        native_version = native_info["techxuexi_version"]
        native_update_logs = native_info["techxuexi_update_log"]

        remote_version = remote_info["techxuexi_version"]
        remote_update_logs = remote_info["techxuexi_update_log"]
        print(color.yellow("[*] " + __INFO))
        print(color.yellow("[*] 程序版本为:{}".format(native_version)))
        print(color.yellow("[*] 最新版本为:{}".format(remote_version)))
        if remote_version > native_version:  # 有新版本
            print(color.red("[*] 当前不是最新版本,建议更新"))
            print(color.red("[*] " + "=" * 60))
            print(color.red("[*] 更新提要:"))
            for log in remote_update_logs:
                if log["version"] > native_version:
                    print(color.red("[*] " + log["version"]))
                    print(color.red(log["info"]))
                else:
                    print(color.yellow("[*] " + __INFO))
                    print(color.yellow("[*] " + __SITE))
                    break
    except:
        print(color.yellow("[*] 版本信息网络错误"))
Beispiel #3
0
def up_info():
    print(color.yellow("[*] 正在联网获取更新信息...(更新显示不会打断之前输入等操作)"))
    __Version = "v20200928"
    __INFO = "TechXueXi最新下载地址为 https://github.com/TechXueXi/TechXueXi"
    try:
        update_log = requests.get(
            "https://techxuexi.vercel.app/Update.html").content.decode("utf8")
        update_log = update_log.split("\n")
        print(color.yellow("[*] " + __INFO))
        print(color.yellow("[*] 程序版本为:{}".format(__Version)))
        print(color.yellow("[*] 最新版本为:{}".format(update_log[1].split("=")[1])))
        if __Version != update_log[1].split("=")[1]:
            print(color.red("[*] 当前不是最新版本,建议更新"))
            print(color.red("[*] =" * 60))
            print(color.red("[*] 更新提要:"))
            for i in update_log[2:]:
                print(color.red("[*] " + i))
    except:
        print(color.yellow("[*] 版本信息网络错误"))
Beispiel #4
0
def check_default_user_cookie():
    default_userId = get_default_userId()
    default_fullname = get_default_fullname()
    default_nickname = get_default_nickname()
    print_list = [color.blue(str(default_userId)),
                  color.blue(default_nickname)]
    print(
        "=" * 60, "\n默认用户ID:{0[0]},默认用户昵称:{0[1]}".format(print_list), end=" ")
    cookies = get_cookie(default_userId)
    if not cookies:
        print(color.red("【无有效cookie信息,需要登录】"))
        return []
    else:
        print(color.green("(cookie信息有效)"))
        return cookies
Beispiel #5
0
def refresh_all_cookies(live_time=8.0,
                        display_score=False):  # cookie有效时间保持在live_time以上
    template_json_str = '''{}'''
    cookies_json_obj = file.get_json_data("user/cookies.json",
                                          template_json_str)
    need_check = False
    valid_cookies = []
    for uid in cookies_json_obj:
        cookies_b64 = cookies_json_obj[uid]
        cookies_bytes = base64.b64decode(cookies_b64)
        cookie_list = pickle.loads(cookies_bytes)
        for d in cookie_list:  # 检查是否过期
            if 'name' in d and 'value' in d and 'expiry' in d and d[
                    "name"] == "token":
                remain_time = (int(d['expiry']) - (int)(time.time())) / 3600
                print(
                    color.green(uid + "_" + get_nickname(uid) + ",登录剩余有效时间:" +
                                str(int(remain_time * 1000) / 1000) + " 小时."),
                    end="")
                if remain_time < 0:
                    print(color.red(" 已过期 需要重新登陆,将自动移除此cookie."))
                    remove_cookie(uid)
                else:
                    # print(color.blue(" 有效"), end="")
                    valid_cookies.append(cookie_list)
                    if remain_time <= live_time:  # 全新cookies的有效时间是12h
                        print(color.red(" 需要刷新"))
                        need_check = True
                        # 暂没有证据表明可以用requests来请求,requests请求的响应不带cookies,不确定会不会更新cookies时间
                        # (但是万一服务端自动更新了cookie,可以试试12h之后再访问呢?则剩余时间直接设为12即可。有空的伙计可以做个实验)
                        # jar = RequestsCookieJar()
                        # for cookie in cookie_list:
                        #     jar.set(cookie['name'], cookie['value'])
                        # new_cookies = requests.get("https://pc.xuexi.cn/points/my-points.html", cookies=jar,
                        #                         headers={'Cache-Control': 'no-cache'}).cookies.get_dict()
                        # 浏览器登陆方式更新cookie,速度较慢但可靠
                        driver_login = Mydriver(nohead=False)
                        driver_login.get_url(
                            "https://www.xuexi.cn/notFound.html")
                        driver_login.set_cookies(cookie_list)
                        driver_login.get_url(
                            'https://pc.xuexi.cn/points/my-points.html')
                        new_cookies = driver_login.get_cookies()
                        driver_login.quit()
                        found_token = False
                        for j in new_cookies:  # 检查token
                            if 'name' in j and j["name"] == "token":
                                found_token = True
                        if not found_token:
                            remove_cookie(uid)  # cookie不含token则无效,删除cookie
                        else:
                            save_cookies(new_cookies)
                    else:
                        print(color.green(" 无需刷新"))
    if need_check:  # 再执行一遍来检查有效情况
        print("再次检查cookies有效时间...")
        refresh_all_cookies()
    elif display_score:
        for cookie in valid_cookies:
            user_id = get_userId(cookie)
            print(color.blue(get_fullname(user_id)) + " 的今日得分:")
            score.show_score(cookie)
Beispiel #6
0
def handle_score_color(score, full_score, colorful=True):
    if int(score) < int(full_score) and colorful:
        return color.red(str(score))+" / "+str(full_score)
    else:
        return str(score)+" / "+str(full_score)
Beispiel #7
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
def video(userId, cookies, video_pointer, scores):
    try:
        if scores["video_num"] < const.video_num_all or scores[
                "video_time"] < const.video_time_all:
            # driver_video = Mydriver(nohead=nohead)
            driver_video = Mydriver(nohead=True)
            # def video_stop_function():
            #     driver_video.quit()
            # threads.regist_stop_function(video_stop_function)
            driver_video.get_url("https://www.xuexi.cn/notFound.html")
            driver_video.set_cookies(cookies)
            links = get_links.get_video_links()
            try_count = 0
            watchvideo_time = 0
            while True:
                if scores["video_num"] < const.video_num_all and try_count < 10:
                    v_num = const.video_num_all - scores["video_num"]
                    for i in range(video_pointer, video_pointer + v_num):
                        driver_video.get_url(links[i])
                        watchvideo_time = 60 + random.randint(5, 15)
                        for j in range(watchvideo_time):
                            if random.random() > 0.5:
                                driver_video.go_js(
                                    'window.scrollTo(0, document.body.scrollHeight/180*{})'
                                    .format(j))
                            print("\r视频数量学习中,视频剩余{}个,本次剩余时间{}秒".format(
                                video_pointer + v_num - i,
                                watchvideo_time - j),
                                  end="")
                            time.sleep(1)
                        driver_video.go_js(
                            'window.scrollTo(0, document.body.scrollHeight)')
                        total, scores = show_score(cookies)
                        if scores["video_num"] >= const.video_num_all:
                            print("检测到视频数量分数已满,退出学习")
                            break
                    video_pointer += v_num
                else:
                    user.save_video_index(userId, video_pointer)
                    break
            try_count = 0
            while True:
                if scores[
                        "video_time"] < const.video_time_all and try_count < 10:
                    num_time = 60
                    driver_video.get_url(links[video_pointer - 1])
                    remaining = (const.video_time_all -
                                 scores["video_time"]) * 1 * num_time
                    for i in range(remaining):
                        if random.random() > 0.5:
                            driver_video.go_js(
                                'window.scrollTo(0, document.body.scrollHeight/{}*{})'
                                .format(remaining, i))
                        print("\r视频时长学习中,视频总时长剩余{}秒".format(remaining - i),
                              end="")
                        time.sleep(1)
                        if i % (60) == 0 and i != remaining:
                            total, scores = show_score(cookies)
                            if scores["video_time"] >= const.video_time_all:
                                print("检测到视频时长分数已满,退出学习")
                                break
                    driver_video.go_js(
                        'window.scrollTo(0, document.body.scrollHeight)')
                    total, scores = show_score(cookies)
                else:
                    break
            if try_count < 10:
                print("视频学习完成")
            else:
                print("视频学习出现异常,请检查 user/article_video_index.json 文件记录")
            driver_video.quit()
        else:
            print("视频之前学完了")
    except Exception as e:
        print(color.red("视频学习检测到异常:" + str(e)))
def article(userId, cookies, article_pointer, scores):
    try:
        if scores["article_num"] < const.article_num_all or scores[
                "article_time"] < const.article_time_all:
            # driver_article = Mydriver(nohead=nohead)
            driver_article = Mydriver(nohead=True)
            # def article_stop_function():
            #     driver_article.quit()
            # threads.regist_stop_function(article_stop_function)
            driver_article.get_url("https://www.xuexi.cn/notFound.html")
            driver_article.set_cookies(cookies)
            links = get_links.get_article_links()
            try_count = 0
            readarticle_time = 0
            while True:
                if scores[
                        "article_num"] < const.article_num_all and try_count < 10:
                    article_remain = const.article_num_all - scores[
                        "article_num"]
                    for i in range(article_pointer,
                                   article_pointer + article_remain):
                        driver_article.get_url(links[i])
                        readarticle_time = 60 + random.randint(5, 15)
                        for j in range(readarticle_time):
                            if random.random() > 0.5:
                                driver_article.go_js(
                                    'window.scrollTo(0, document.body.scrollHeight/120*{})'
                                    .format(j))
                            print("\r文章数量学习中,文章剩余{}篇,本篇剩余时间{}秒".format(
                                article_pointer + article_remain - i,
                                readarticle_time - j),
                                  end="")
                            time.sleep(1)
                        driver_article.go_js(
                            'window.scrollTo(0, document.body.scrollHeight)')
                        total, scores = show_score(cookies)
                        if scores["article_num"] >= const.article_num_all:
                            print("检测到文章数量分数已满,退出学习")
                            break
                    article_pointer += article_remain
                else:
                    user.save_article_index(userId, article_pointer)
                    break
            try_count = 0
            while True:
                if scores[
                        "article_time"] < const.article_time_all and try_count < 10:
                    num_time = 60
                    driver_article.get_url(links[article_pointer - 1])
                    remaining = (const.article_time_all -
                                 scores["article_time"]) * 1 * num_time
                    for i in range(remaining):
                        if random.random() > 0.5:
                            driver_article.go_js(
                                'window.scrollTo(0, document.body.scrollHeight/{}*{})'
                                .format(remaining, i))
                        print("\r文章时长学习中,文章总时长剩余{}秒".format(remaining - i),
                              end="")
                        time.sleep(1)
                        if i % (60) == 0 and i != remaining:
                            total, scores = show_score(cookies)
                            if scores["article_time"] >= const.article_time_all:
                                print("检测到文章时长分数已满,退出学习")
                                break
                    driver_article.go_js(
                        'window.scrollTo(0, document.body.scrollHeight)')
                    total, scores = show_score(cookies)
                else:
                    break
            if try_count < 10:
                print("文章学习完成")
            else:
                print("文章学习出现异常,请检查 user/article_video_index.json 文件记录")
            driver_article.quit()
        else:
            print("文章之前学完了")
    except Exception as e:
        print(color.red("文章学习检测到异常:" + str(e)))