Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
多处大更新:
Browse files Browse the repository at this point in the history
- pdlearn/historical/dingding.py
  - 移除钉钉登陆相关代码:get_dd、dd_login_status、save_dingding、load_dingding
- pdlearn/historical/mydriver.py
  - #移除钉钉登陆相关代码:dd_login
- pdlearn/historical/pandalearning.py
  - 移除获取cookie和a_log v_log d_log的user_flag函数,放至historical文件夹
- pdlearn/historical/user.py
  - 移除check_dd钉钉登陆、get_user获取用户文件夹、check_uname检查用户文件夹
  - 移除get_a_log文章学习计数、get_v_log视频观看计数、get_d_log每日每周专项答题计数
- pdlearn/answer_question.py
  - daily、weekly、zhuanxiang中移除无用的d_log和d_num
- pdlearn/article_video.py
  - article、video函数中,a_log更名为article_pointer,v_log更名为video_pointer
  - 使用json文件和userId与值的映射存储原来的a_log v_log
  - 尝试制作线程退出没有成功
- pdlearn/color.py
  - 使用第三方库colorama使命令行输出彩色文字,更为直观
  - 定义red yellow blue green的颜色文字转换函数
- pdlearn/config.py
  - 将原主文件中的cfg相关部分单独放进config.py中管理cfg对象
- pdlearn/file.py
  - 文件接口,check_directory检查文件夹存在不存在创建文件夹、get_json_data,save_json_data,json数据的存取
- pdlearn/mydriver.py
  - 使用user/cookies.json的键值对映射存储各用户cookie
  - 获取cookie的过程中发生错误,打印错误信息方便程序改进
  - get_cookie_from_cache以至user.py的get_cookie统一管理
- pdlearn/score.py
  - get_userId以至user.py统一管理
- pdlearn/threads.py
  - 尝试制作线程退出没有成功(无法解决的bug:按键盘ctrl-C会导致程序直接僵死)
- pdlearn/user.py
  - 优化了一些import
  - get_userId获取用户唯一编号
  - get_fullname获取用户id和昵称组成的的全称
  - get_nickname获取昵称
  - save_fullname保存一个新建用户名(id->nickname映射)
  - get_user_status或许默认用户和用户映射的状态,如没有,新建一个
  - update_last_user更新默认用户id
  - save_user_status保存用户状态
  - get_cookie根据userId获取保存的有效cookie,如没有,新建一个
  - save_cookies保存浏览器登陆获得的cookie,获取userId并保存id->cookie映射
  - get_article_video_json获取视频文章记录
  - get_index、save_index存取记录
  - get_article_index、save_article_index存取文章记录
  - get_video_index、save_video_index存取视频记录
  - get_default_userId、get_default_nickname、get_default_fullname获取默认
  - check_default_user_cookie检查默认用户cookie是否有效并返回cookie
  - list_user如有多用户,列出多用户(不要求使用者选择一个)
  - select_user要求使用者选择一个用户信息(半成品)
  - shutdown函数改用Windows命令行的timeout,计时中按任意键即可退出程序
- pdlearn/version.py
  - 基于color/py,将更新信息显示为黄色,以区别常规信息,更新内容显示为红色
  - (优化了一些不必要的print...)
  - 拼写:updata -> update
- pandalearning.py
  - 移除cfg统一管理
  - 优化了一些import
  - 优化了banner打印,多字符串拼接或许优雅一些
  - 检查默认用户cookie,检查多用户
  - 如cookie无效,打开浏览器登陆,保存cookie,更新默认用户id
  - 使用article_pointer、video_pointer代替原来的a_log v_log
  - 视频文章学习函数增加uid参数,便于学习完成后保存用户学习进度
  - 删除无用的原d_log(答题记录)
  • Loading branch information
TCPsoftware committed Feb 19, 2021
1 parent c65aaae commit 52120f1
Show file tree
Hide file tree
Showing 15 changed files with 541 additions and 294 deletions.
81 changes: 35 additions & 46 deletions SourcePackages/pandalearning.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,17 @@
import sys
import time
import math
from time import sleep
from sys import argv
from pdlearn import version
from pdlearn import user
from pdlearn import dingding
from pdlearn import score
from pdlearn import color
from pdlearn import threads
from pdlearn.config import cfg
from pdlearn.mydriver import Mydriver
from pdlearn.score import show_score
from pdlearn.article_video import *
from pdlearn.answer_question import *
from configparser import ConfigParser
cfg = ConfigParser()
os.chdir(sys.path[0]) # 切换pwd到python文件路径,避免找不到相对路径下的ini
cfg.read('./config/main.ini', encoding='utf-8')


def user_flag(dd_status, uname):
if False and dd_status:
cookies = dingding.dd_login_status(uname, has_dd=True)
else:
# if (input("是否保存钉钉帐户密码,保存后可后免登陆学习(Y/N) ")) not in ["y", "Y"]:
if True:
cookies = Mydriver.get_cookie_from_cache()
if not cookies:
print("未找到有效登录信息,需要登录")
driver_login = Mydriver(nohead=False)
cookies = driver_login.login()
driver_login.quit()
else:
cookies = dingding.dd_login_status(uname)
a_log = user.get_a_log(uname)
v_log = user.get_v_log(uname)
d_log = user.get_d_log(uname)

return cookies, a_log, v_log, d_log
from pdlearn.article_video import article, video
from pdlearn.answer_question import daily, weekly, zhuanxiang


def get_argv():
Expand All @@ -64,42 +39,56 @@ def get_argv():
# 0 读取版本信息
start_time = time.time()
if(cfg['display']['banner'] != "false"): # banner文本直接硬编码,不要放在ini中
print("=" * 60 + '''
科技强国官方网站:https://techxuexi.js.org
Github地址:https://github.com/TechXueXi
使用本项目,必须接受以下内容,否则请立即退出:
- TechXueXi 仅额外提供给“爱党爱国”且“工作学业繁重”的人
- 项目开源协议 LGPL-3.0
- 不得利用本项目盈利
另外,我们建议你参与一个维护劳动法的项目:
https://996.icu/ 或 https://github.com/996icu/996.ICU/blob/master/README_CN.md''')
print("=" * 60, '\n', '''TechXueXi 现支持以下模式(答题时请值守电脑旁处理少部分不正常的题目):''')
print("=" * 60 + \
'\n 科技强国官方网站:https://techxuexi.js.org' + \
'\n Github地址:https://github.com/TechXueXi' + \
'\n使用本项目,必须接受以下内容,否则请立即退出:' + \
'\n - TechXueXi 仅额外提供给“爱党爱国”且“工作学业繁重”的人' + \
'\n - 项目开源协议 LGPL-3.0' + \
'\n - 不得利用本项目盈利' + \
'\n另外,我们建议你参与一个维护劳动法的项目:' + \
'\nhttps://996.icu/ 或 https://github.com/996icu/996.ICU/blob/master/README_CN.md')
cookies = user.check_default_user_cookie()
user.list_user()
# user.select_user()
print("=" * 60, '''\nTechXueXi 现支持以下模式(答题时请值守电脑旁处理少部分不正常的题目):''')
print(cfg['base']['ModeText'] + '\n' + "=" * 60) # 模式提示文字请在 ./config/main.ini 处修改。
TechXueXi_mode = input("请选择模式(输入对应数字)并回车: ")

info_shread = threads.MyThread("获取更新信息...", version.up_info)
info_shread.start()
# 1 创建用户标记,区分多个用户历史纪录
dd_status, uname = user.get_user()
cookies, a_log, v_log, d_log = user_flag(dd_status, uname)
uid = user.get_default_userId()
if not cookies:
print("未找到有效登录信息,需要登录")
driver_login = Mydriver(nohead=False)
cookies = driver_login.login()
driver_login.quit()
user.save_cookies(cookies)
uid = user.get_userId(cookies)
user_fullname = user.get_fullname(uid)
user.update_last_user(uid)
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("文章学习", article, cookies, a_log, scores, lock=lock)
video_thread = threads.MyThread("视频学习", video, cookies, v_log, scores, lock=lock)
article_thread = threads.MyThread("文章学习", article, uid, cookies, article_index, scores, lock=lock)
video_thread = threads.MyThread("视频学习", 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, d_log, scores)
daily(cookies, scores)
if TechXueXi_mode in ["3"]:
print('开始每周答题……')
weekly(cookies, d_log, scores)
weekly(cookies, scores)
print('开始专项答题……')
zhuanxiang(cookies, d_log, scores)
zhuanxiang(cookies, scores)

seconds_used = int(time.time() - start_time)
print("总计用时 " + str(math.floor(seconds_used / 60)) + " 分 " + str(seconds_used % 60) + " 秒")
Expand Down
27 changes: 3 additions & 24 deletions SourcePackages/pdlearn/answer_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def check_delay():
time.sleep(delay_time)


def daily(cookies, d_log, scores):
def daily(cookies, scores):
if scores["daily"] < const.daily_all:
# driver_daily = Mydriver(nohead=nohead) time.sleep(random.randint(5, 15))
driver_daily = Mydriver(nohead=False)
Expand All @@ -24,7 +24,6 @@ def daily(cookies, d_log, scores):
try_count = 0

if scores["daily"] < const.daily_all:
d_num = const.daily_all - scores["daily"]
letters = list("ABCDEFGHIJKLMN")
driver_daily.get_url('https://pc.xuexi.cn/points/my-points.html')
driver_daily.click_xpath('//*[@id="app"]/div/div[2]/div/div[3]/div[2]/div[5]/div[2]/div[2]/div')
Expand Down Expand Up @@ -116,18 +115,12 @@ def daily(cookies, d_log, scores):
else:
print("题目类型非法")
break
# print("\r每日答题中,题目剩余{}题".format(d_log + d_num - i), end="")
time.sleep(1)
d_log += d_num

total, scores = show_score(cookies)
if scores["daily"] >= const.daily_all:
print("检测到每日答题分数已满,退出学习")
driver_daily.quit()
else:
with open("./user/{}/d_log".format(1), "w", encoding="utf8") as fp:
fp.write(str(d_log))
# break
try:
driver_daily.quit()
except Exception as e:
Expand All @@ -136,7 +129,7 @@ def daily(cookies, d_log, scores):
print("每日答题之前学完了")


def weekly(cookies, d_log, scores):
def weekly(cookies, scores):
if scores["weekly"] < const.weekly_all:
# driver_weekly = Mydriver(nohead=nohead) time.sleep(random.randint(5, 15))
driver_weekly = Mydriver(nohead=False)
Expand All @@ -149,7 +142,6 @@ def weekly(cookies, d_log, scores):
try_count = 0

if scores["weekly"] < const.weekly_all:
d_num = const.weekly_all - scores["weekly"]
letters = list("ABCDEFGHIJKLMN")
driver_weekly.get_url('https://pc.xuexi.cn/points/my-points.html')
driver_weekly.click_xpath('//*[@id="app"]/div/div[2]/div/div[3]/div[2]/div[6]/div[2]/div[2]/div')
Expand Down Expand Up @@ -306,18 +298,12 @@ def weekly(cookies, d_log, scores):
else:
print("题目类型非法")
break
# print("\r每周答题中,题目剩余{}题".format(d_log + d_num - i), end="")
time.sleep(1)
d_log += d_num

total, scores = show_score(cookies)
if scores["weekly"] >= const.weekly_all:
print("检测到每周答题分数已满,退出学习")
driver_weekly.quit()
else:
with open("./user/{}/d_log".format(1), "w", encoding="utf8") as fp:
fp.write(str(d_log))
# break
try:
driver_weekly.quit()
except Exception as e:
Expand All @@ -326,7 +312,7 @@ def weekly(cookies, d_log, scores):
print("每周答题之前学完了")


def zhuanxiang(cookies, d_log, scores):
def zhuanxiang(cookies, scores):
if scores["zhuanxiang"] < const.zhuanxiang_all:
# driver_zhuanxiang = Mydriver(nohead=nohead) time.sleep(random.randint(5, 15))
driver_zhuanxiang = Mydriver(nohead=False)
Expand All @@ -339,7 +325,6 @@ def zhuanxiang(cookies, d_log, scores):
try_count = 0

if scores["zhuanxiang"] < const.zhuanxiang_all:
d_num = const.zhuanxiang_all - scores["zhuanxiang"]
letters = list("ABCDEFGHIJKLMN")
driver_zhuanxiang.get_url('https://pc.xuexi.cn/points/my-points.html')
driver_zhuanxiang.click_xpath('//*[@id="app"]/div/div[2]/div/div[3]/div[2]/div[7]/div[2]/div[2]/div')
Expand Down Expand Up @@ -455,18 +440,12 @@ def zhuanxiang(cookies, d_log, scores):
else:
print("题目类型非法")
break
# print("\r专项答题中,题目剩余{}题".format(d_log + d_num - i), end="")
time.sleep(1)
d_log += d_num

total, scores = show_score(cookies)
if scores["zhuanxiang"] >= const.zhuanxiang_all:
print("检测到专项答题分数已满,退出学习")
driver_zhuanxiang.quit()
else:
with open("./user/{}/d_log".format(1), "w", encoding="utf8") as fp:
fp.write(str(d_log))
# break
try:
driver_zhuanxiang.quit()
except Exception as e:
Expand Down
Loading

1 comment on commit 52120f1

@cjh0613
Copy link

@cjh0613 cjh0613 commented on 52120f1 Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TCPsoftware 这次修改中,建立的config.pyhttps://github.com/TechXueXi/TechXueXi/blob/d5b864491e6e8727e0618f81d3dac3d29aa72be6/SourcePackages/pdlearn/config.py

import os
import sys
from configparser import ConfigParser

cfg = ConfigParser()

os.chdir(sys.path[0]) # 切换pwd到python文件路径,避免找不到相对路径下的ini  ## 应该是这里
if(not os.path.exists("config")):
    os.mkdir("config")
    if(not os.path.exists("config/main.ini")):
        # write_default_ini()
        input("缺少配置文件 config/main.ini,请检查.")
        exit()
cfg.read('./config/main.ini', encoding='utf-8')

存在bug,造成打包的文件报错:

Traceback (most recent call last):
  File "pandalearning.py", line 11, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module
  File "pdlearn\config.py", line 7, in <module>
NotADirectoryError: [WinError 267] 目录名称无效。: '……\\base_library.zip'
[53664] Failed to execute script pandalearning

请尽快修复,谢谢

Please sign in to comment.