Esempio n. 1
0
File: exam.py Progetto: tyzhxf/xxqg
def to_exam(browser: XuexiChrome, exam_type: check.CheckResType):
    """
    根据参数题目类型进入对应的题目
    :param browser: browser
    :param exam_type: 题目类型(日、周、专)
    :return:
    """
    browser.xuexi_get('https://www.xuexi.cn/')
    browser.xuexi_get('https://pc.xuexi.cn/points/my-points.html')
    sleep(round(uniform(1, 2), 2))

    # 获取答题按钮族
    exam = browser.find_elements(by=By.CLASS_NAME, value='big')
    if exam_type == check.CheckResType.DAILY_EXAM:
        daily = exam[4]
        browser.execute_script('arguments[0].scrollIntoView();', daily)
        sleep(round(uniform(1, 2), 2))
        click(browser, daily)
        sleep(round(uniform(2, 4), 2))
        run_exam(browser)
    elif exam_type == check.CheckResType.WEEKLY_EXAM:
        weekly = exam[5]
        browser.execute_script('arguments[0].scrollIntoView();', weekly)
        sleep(round(uniform(1, 2), 2))
        click(browser, weekly)
        check_exam(browser, exam_type)
    elif exam_type == check.CheckResType.SPECIAL_EXAM:
        special = exam[6]
        browser.execute_script('arguments[0].scrollIntoView();', special)
        sleep(round(uniform(1, 2), 2))
        click(browser, special)
        check_exam(browser, exam_type)
Esempio n. 2
0
def scan_article(browser: XuexiChrome):
    articlePath = 'data/articles.json'
    with open(articlePath, 'r', encoding='utf-8') as f:
        articles = f.read()
    # print(articles)
    articles = loads(articles)
    while True:
        randIndex = randint(0, len(articles) - 1)
        if articles[randIndex]['type'] != 'tuwen':
            del articles[randIndex]
            continue
        else:
            break
    url = articles[randIndex]['url']
    browser.xuexi_get(
        'https://www.xuexi.cn/d184e7597cc0da16f5d9f182907f1200/9a3668c13f6e303932b5e0e100fc248b.html'
    )
    browser.xuexi_get(url)

    # 看文章随机70-75秒
    totalTime = randint(70, 75)
    print('--> 正在浏览:《' + articles[randIndex]['title'] + '》')
    with Progress() as progress:
        task = progress.add_task("--> [cyan]浏览进度:", total=totalTime)
        while not progress.finished:
            browser.execute_script('window.scrollBy(' + str(randint(2, 9)) +
                                   ',' + str(randint(15, 31)) + ')')
            sleepTime = round(uniform(1, 5), 2)
            progress.update(task, advance=sleepTime)
            sleep(sleepTime)

    print()
    del articles[randIndex]
    with open(articlePath, 'w', encoding='utf-8') as f:
        f.write(dumps(articles, ensure_ascii=False, indent=4))
Esempio n. 3
0
def login(browser: XuexiChrome):
    """
    扫码登录流程,将登录的最终结果返回给主程序
    :param browser: browser
    :return: bool,表示是否登录成功
    """
    browser.xuexi_get('https://pc.xuexi.cn/points/my-points.html')
    sleep(2.5)
    print('--> 请在5分钟内扫码完成登录')
    browser.implicitly_wait(10)
    qglogin = browser.find_element(by=By.ID, value='qglogin')
    browser.execute_script('arguments[0].scrollIntoView();', qglogin)

    for i in range(60):
        if browser.current_url == 'https://pc.xuexi.cn/points/my-points.html':
            print('--> 登录成功')
            return True
        sleep(5)
    return False
Esempio n. 4
0
File: exam.py Progetto: wdj6868/xxqg
def to_exam(browser: XuexiChrome, examType: check.CheckResType):
    """
    根据参数题目类型进入对应的题目
    :param browser: browser
    :param examType: 题目类型(日、周、专)
    :return:
    """
    browser.xuexi_get('https://www.xuexi.cn/')
    browser.xuexi_get('https://pc.xuexi.cn/points/my-points.html')
    sleep(round(uniform(1, 2), 2))

    if examType == check.CheckResType.DAILY_EXAM:
        daily = browser.find_element_by_xpath(
            '//*[@id="app"]/div/div[2]/div/div[3]/div[2]/div[5]/div[2]/div[2]/div'
        )
        browser.execute_script('arguments[0].scrollIntoView();', daily)
        sleep(round(uniform(1, 2), 2))
        click(browser, daily)
        sleep(round(uniform(2, 4), 2))
        run_exam(browser)
    elif examType == check.CheckResType.WEEKLY_EXAM:
        weekly = browser.find_element_by_xpath(
            '//*[@id="app"]/div/div[2]/div/div[3]/div[2]/div[6]/div[2]/div[2]/div'
        )
        browser.execute_script('arguments[0].scrollIntoView();', weekly)
        sleep(round(uniform(1, 2), 2))
        click(browser, weekly)
        check_exam(browser, examType)
    elif examType == check.CheckResType.SPECIAL_EXAM:
        special = browser.find_element_by_xpath(
            '//*[@id="app"]/div/div[2]/div/div[3]/div[2]/div[7]/div[2]/div[2]/div'
        )
        browser.execute_script('arguments[0].scrollIntoView();', special)
        sleep(round(uniform(1, 2), 2))
        click(browser, special)
        check_exam(browser, examType)
Esempio n. 5
0
def watch_video(browser: XuexiChrome):
    videoPath = 'data/videos.json'
    with open(videoPath, 'r', encoding='utf-8') as f:
        videos = f.read()
    # print(videos)
    videos = loads(videos)
    while True:
        randIndex = randint(0, len(videos) - 1)
        if videos[randIndex]['type'] != 'shipin':
            del videos[randIndex]
            continue
        else:
            break

    url = videos[randIndex]['url']
    browser.xuexi_get(
        'https://www.xuexi.cn/0809b8b6ab8a81a4f55ce9cbefa16eff/ae60b027cb83715fd0eeb7bb2527e88b.html'
    )
    browser.xuexi_get(
        'https://www.xuexi.cn/4426aa87b0b64ac671c96379a3a8bd26/db086044562a57b441c24f2af1c8e101.html#t1jk1cdl7l-5'
    )
    browser.xuexi_get(url)
    video = browser.find_element_by_xpath(
        '/html/body/div/div/section/div/div/div/div/div[2]/section/div/div/div/div/div/div/div/div[1]/div[2]/div/div[1]/div[1]/div/video'
    )
    start = browser.find_element_by_xpath(
        '/html/body/div/div/section/div/div/div/div/div[2]/section/div/div/div/div/div/div/div/div[1]/div[2]/div/div[1]/div[1]/div/div[1]'
    )
    sleep(round(uniform(1, 3), 2))
    browser.execute_script('arguments[0].scrollIntoView();', video)
    try:
        start.click()
    except BaseException:
        pass

    # 看视频随机65-75秒
    totalTime = randint(65, 75)
    print('--> 正在观看:《' + videos[randIndex]['title'] + '》')
    with Progress() as progress:
        task = progress.add_task("--> [red]观看进度:", total=totalTime)
        while not progress.finished:
            sleepTime = round(uniform(1, 3), 2)
            progress.update(task, advance=sleepTime)
            sleep(sleepTime)

    print()

    del videos[randIndex]
    with open(videoPath, 'w', encoding='utf-8') as f:
        f.write(dumps(videos, ensure_ascii=False, indent=4))
Esempio n. 6
0
def check_task(browser: XuexiChrome):
    """
    检查任务项并返回给主程序
    :param browser: browser
    :return: CheckResType:任务类型
    """
    # table = PrettyTable(["每日登录", "选读文章", "视频数量", "视频时长", "每日答题", "每周答题", "专项答题", "今日累计积分", "成长总积分"])
    table = Table(show_header=True, header_style="bold black")
    table.add_column("每日登录", justify='center')
    table.add_column("选读文章", justify='center')
    table.add_column("视频数量", justify='center')
    table.add_column("视频时长", justify='center')
    table.add_column("每日答题", justify='center')
    table.add_column("每周答题", justify='center')
    table.add_column("专项答题", justify='center')
    table.add_column("今日累计积分", justify='center')
    table.add_column("成长总积分", justify='center')
    tableRow = []
    settingsPath = 'data/settings.json'
    with open(settingsPath, 'r', encoding='utf-8') as f:
        settings = f.read()
    settings = loads(settings)

    exam_temp_Path = './data/exam_temp.json'
    with open(exam_temp_Path, 'r', encoding='utf-8') as f:
        exam_temp = f.read()
    exam_temp = loads(exam_temp)

    res = CheckResType.NULL
    browser.xuexi_get('https://www.xuexi.cn/index.html')
    browser.xuexi_get('https://pc.xuexi.cn/points/my-points.html')

    # 获取各任务项积分
    scores = browser.find_elements_by_class_name('my-points-card-text')
    for score in scores:
        tableRow.append(score.text.strip())

    # 今日积分
    todayPoints = browser.find_element_by_xpath(
        '//*[@id="app"]/div/div[2]/div/div[2]/div[2]/span[3]')
    tableRow.append(todayPoints.text.strip())
    # 总积分
    allPoints = browser.find_element_by_xpath(
        '//*[@id="app"]/div/div[2]/div/div[2]/div[2]/span[1]')
    tableRow.append(allPoints.text.strip())

    # 打印表格
    table.add_row(tableRow[0], tableRow[1], tableRow[2], tableRow[3],
                  tableRow[4], tableRow[5], tableRow[6], tableRow[7] + '分',
                  tableRow[8] + '分')
    print(table)

    if settings['浏览文章'] == "true" and scores[1].text != '12分/12分':
        res = CheckResType.ARTICLE
    if settings['观看视频'] == "true" and (scores[2].text != '6分/6分'
                                       or scores[3].text != '6分/6分'):
        if res == CheckResType.ARTICLE:
            res = CheckResType.ARTICLE_AND_VIDEO
        else:
            res = CheckResType.VIDEO

    # 检查设置文件
    if settings['自动答题'] != 'true':
        return res

    dayOfWeek = str(datetime.now().isoweekday())
    if settings['每日答题'] == 'true' and res == CheckResType.NULL and scores[
            4].text != '5分/5分':
        if settings['答题时间设置']['是否启用(关闭则每天都答题)'] != 'true' or (
                settings['答题时间设置']['是否启用(关闭则每天都答题)'] == 'true'
                and dayOfWeek in settings['答题时间设置']['答题类型(数字代表星期几)']['每日答题']):
            res = CheckResType.DAILY_EXAM
    if exam_temp['WEEKLY_EXAM'] == 'true' and settings[
            '每周答题'] == 'true' and res == CheckResType.NULL and scores[
                5].text != '5分/5分':
        if settings['答题时间设置']['是否启用(关闭则每天都答题)'] != 'true' or (
                settings['答题时间设置']['是否启用(关闭则每天都答题)'] == 'true'
                and dayOfWeek in settings['答题时间设置']['答题类型(数字代表星期几)']['每周答题']):
            res = CheckResType.WEEKLY_EXAM
    if exam_temp['SPECIAL_EXAM'] == 'true' and settings[
            '专项答题'] == 'true' and res == CheckResType.NULL and scores[
                6].text != '10分/10分':
        if settings['答题时间设置']['是否启用(关闭则每天都答题)'] != 'true' or (
                settings['答题时间设置']['是否启用(关闭则每天都答题)'] == 'true'
                and dayOfWeek in settings['答题时间设置']['答题类型(数字代表星期几)']['专项答题']):
            res = CheckResType.SPECIAL_EXAM

    return res
Esempio n. 7
0
def logout(browser: XuexiChrome):
    browser.xuexi_get('https://www.xuexi.cn/')
    sleep(round(uniform(1, 2), 2))
    logout_btn = browser.find_element(by=By.CLASS_NAME, value='logged-link')
    logout_btn.click()
Esempio n. 8
0
def logout(browser: XuexiChrome):
    browser.xuexi_get('https://www.xuexi.cn/')
    sleep(round(uniform(1, 2), 2))
    logoutBtn = browser.find_element_by_xpath('//*[@id="root"]/div/header/div[2]/div[2]/span/a')
    logoutBtn.click()