Skip to content

Commit

Permalink
版本 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pooneyy committed Aug 8, 2024
1 parent 45505af commit 9922cd3
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 80 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ build
dist
env
*.bat
*.sh
*.exe
*.json
*.spec
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@

- 版本 2.0 at 2023-09-18 21:57:16
- 优化:使用账号密码登录,登录相关的代码来自[Coaixy/weiban-tool/enco.py](https://github.com/Coaixy/weiban-tool/blob/bf08fe823953afa834b49fe8d7e7a1d5abf7e605/enco.py)

- 版本 2.1 at 2024-08-08 22:18:58
- 优化:优化多账号。
- 更新:解决观看课程后的验证码,相关代码来自[Fix:Repair cannot be completed · Coaixy/weiban-tool@228d312](https://github.com/Coaixy/weiban-tool/commit/228d312c6ec2a061e60aefa2f5ecb4aedeb4307e)
146 changes: 81 additions & 65 deletions Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,18 @@
'''这个常量的作用是暂存学校名,当同时输入的多个帐号来自同一个学校,用此避免重复地输入学校名'''

class main:
tenantCode = 0
userId = ""
x_token = ""
userProjectId = ""
realName = ""
taskName = ""
resourceNames = ['第0项']
headers = {'x-token': "",
"User-agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Mobile Safari/537.36 Edg/103.0.1264.77"
}
headers = { 'x-token': "",
"User-agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Mobile Safari/537.36 Edg/103.0.1264.77"
}

def __init__(self, code, id, token, realName):
self.tenantCode = code
self.userId = id
self.x_token = token
self.realName = realName
self.userProjectId = []
self.taskName = []
self.resourceNames = ['第0项']

def init(self):
self.headers['x-token'] = self.x_token
Expand Down Expand Up @@ -60,50 +56,50 @@ def get_Project_Info(self):
data = json.loads(response.text)['data']
if len(data) <= 0:self.userProjectId = ''
else:
self.userProjectId = data[0]["userProjectId"]
self.taskName = data[0]["projectName"]
self.userProjectId = [i["userProjectId"] for i in data]
self.taskName = [i["projectName"] for i in data]

def getRealName(self):
url = f"https://weiban.mycourse.cn/pharos/my/getInfo.do?timestamp={int(time.time())}"
data = {
'tenantCode': self.tenantCode,
'userId': self.userId
}
response = requests.post(url, data=data, headers=self.headers)
text = response.text
data = json.loads(text)
return data['data']['realName']
# def getRealName(self):
# url = f"https://weiban.mycourse.cn/pharos/my/getInfo.do?timestamp={int(time.time())}"
# data = {
# 'tenantCode': self.tenantCode,
# 'userId': self.userId
# }
# response = requests.post(url, data=data, headers=self.headers)
# text = response.text
# data = json.loads(text)
# return data['data']['realName']

def getTaskName(self):
url = f"https://weiban.mycourse.cn/pharos/index/listStudyTask.do?timestamp={int(time.time())}"
data = {
'tenantCode': self.tenantCode,
'userId': self.userId,
'limit': 2
}
response = requests.post(url, data=data, headers=self.headers)
text = response.text
data = json.loads(text)
for i in data['data']:
if self.userProjectId in i['userProjectId']:taskName = i['projectName']
return taskName
# def getTaskName(self):
# url = f"https://weiban.mycourse.cn/pharos/index/listStudyTask.do?timestamp={int(time.time())}"
# data = {
# 'tenantCode': self.tenantCode,
# 'userId': self.userId,
# 'limit': 2
# }
# response = requests.post(url, data=data, headers=self.headers)
# text = response.text
# data = json.loads(text)
# for i in data['data']:
# if self.userProjectId in i['userProjectId']:taskName = i['projectName']
# return taskName

def getProgress(self):
url = "https://weiban.mycourse.cn/pharos/project/showProgress.do"
data = {
'userProjectId': self.userProjectId,
'tenantCode': self.tenantCode,
'userId': self.userId
}
response = requests.post(url, data=data, headers=self.headers)
text = response.text
data = json.loads(text)
return data['data']['progressPet']
# def getProgress(self):
# url = "https://weiban.mycourse.cn/pharos/project/showProgress.do"
# data = {
# 'userProjectId': self.userProjectId,
# 'tenantCode': self.tenantCode,
# 'userId': self.userId
# }
# response = requests.post(url, data=data, headers=self.headers)
# text = response.text
# data = json.loads(text)
# return data['data']['progressPet']

def getCategory(self, chooseType):
def getCategory(self, j, chooseType):
url = "https://weiban.mycourse.cn/pharos/usercourse/listCategory.do"
data = {
'userProjectId': self.userProjectId,
'userProjectId': self.userProjectId[j],
'tenantCode': self.tenantCode,
'userId': self.userId,
'chooseType': chooseType
Expand All @@ -118,12 +114,12 @@ def getCategory(self, chooseType):
result.append(i['categoryCode'])
return result

def getCourse(self, chooseType):
def getCourse(self, j, chooseType):
url = "https://weiban.mycourse.cn/pharos/usercourse/listCourse.do"
result = []
for i in self.getCategory(chooseType):
for i in self.getCategory(j ,chooseType):
data = {
"userProjectId": self.userProjectId,
"userProjectId": self.userProjectId[j],
"tenantCode": self.tenantCode,
"userId": self.userId,
"chooseType": chooseType,
Expand All @@ -138,12 +134,12 @@ def getCourse(self, chooseType):
result.append(i["resourceId"])
return result

def getFinishIdList(self, chooseType):
def getFinishIdList(self, j, chooseType):
url = "https://weiban.mycourse.cn/pharos/usercourse/listCourse.do"
result = {}
for i in self.getCategory(chooseType):
for i in self.getCategory(j, chooseType):
data = {
"userProjectId": self.userProjectId,
"userProjectId": self.userProjectId[j],
"tenantCode": self.tenantCode,
"userId": self.userId,
"chooseType": chooseType,
Expand All @@ -164,9 +160,9 @@ def getFinishIdList(self, chooseType):
return result


async def start(self,courseId):
async def start(self, i, courseId):
data = {
"userProjectId": self.userProjectId,
"userProjectId": self.userProjectId[i],
"tenantCode": self.tenantCode,
"userId": self.userId,
"courseId": courseId,
Expand All @@ -186,21 +182,17 @@ async def start(self,courseId):
)
print(f"start:{courseId}\r",end='')

def finish(self, courseId, finishId):
def finish(self, i, courseId, finishId):
get_url_url = "https://weiban.mycourse.cn/pharos/usercourse/getCourseUrl.do"
finish_url = "https://weiban.mycourse.cn/pharos/usercourse/v1/{}.do"
finish_url = "https://weiban.mycourse.cn/pharos/usercourse/v2/{}.do"
data = {
"userProjectId": self.userProjectId,
"userProjectId": self.userProjectId[i],
"tenantCode": self.tenantCode,
"userId": self.userId,
"courseId": courseId,
}
raw_data = requests.post(get_url_url, data=data, headers=self.headers)
url = json.loads(raw_data.text.encode().decode("unicode-escape"))["data"]
token = url[url.find("methodToken="): url.find("&csCom")].replace(
"methodToken=", ""
)
# print(token)
requests.post(get_url_url, data=data, headers=self.headers)
token = self.get_method_token(finishId)
finish_url = finish_url.format(token)
ts = self.__get_timestamp().replace(".", "")
param = {
Expand All @@ -212,6 +204,30 @@ def finish(self, courseId, finishId):
requests.get(finish_url, params=param, headers=self.headers).text
print(f"{self.realName} Finish:{courseId}")

def get_method_token(self, course_id):
url = "https://weiban.mycourse.cn/pharos/usercourse/getCaptcha.do"
params = {
"userCourseId": course_id,
"userProjectId": self.userProjectId,
"userId": self.userId,
"tenantCode": self.tenantCode
}
text = requests.get(url, headers=self.headers, params=params).text
question_id = json.loads(text)['captcha']['questionId']
url = "https://weiban.mycourse.cn/pharos/usercourse/checkCaptcha.do"
params = {
"userCourseId": course_id,
"userProjectId": self.userProjectId,
"userId": self.userId,
"tenantCode": self.tenantCode,
"questionId": question_id
}
data = {
"coordinateXYs": "[{\"x\":199,\"y\":448},{\"x\":241,\"y\":466},{\"x\":144,\"y\":429}]"
}
text = requests.post(url, headers=self.headers, params=params, data=data).text
return json.loads(text)['data']['methodToken']

def fill_key(key):
key_size = 128
filled_key = key.ljust(key_size // 8, b'\x00')
Expand Down
32 changes: 17 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ async def weibanTask(user):
main.init()
try:
main.get_Project_Info()
taskName = main.taskName
print(f"开始进行 {realName} 的任务:{taskName}")
# 获取列表
for chooseType in [2,3]:
finishIdList = main.getFinishIdList(chooseType)
taskName = main.taskName # 这是一个列表
for i in range(len(main.userProjectId)):
print(f"开始进行 {realName} 的任务:{taskName[i]}")
index = 1
for i in main.getCourse(chooseType):
print(f"{realName} 开始学习 {main.resourceNames[index]} {index} / {len(finishIdList)}")
await main.start(i)
await asyncio.sleep(random.randint(15,20))
main.finish(i, finishIdList[i])
print(f"{realName} 完成学习 {main.resourceNames[index]}")
index += 1
print(f"{id} {realName} 的任务已完成")
# 获取列表
for chooseType in [2,3]:
finishIdList = main.getFinishIdList(i, chooseType)
for courseId in main.getCourse(i, chooseType):
print(f"{realName} 开始学习 {main.resourceNames[index]} {index} / {len(finishIdList)}")
await main.start(i, courseId)
await asyncio.sleep(random.randint(15,20))
main.finish(i, courseId, finishIdList[courseId])
print(f"{realName} 完成学习 {main.resourceNames[index]}")
index += 1
print(f"\033[0;31;32m{id} {realName} 的任务已完成\033[0m")
with open("config.json", "r+", encoding='utf8') as file:
config = json.load(file)
for i in config['Accounts']:
Expand All @@ -44,10 +45,11 @@ async def weibanTask(user):
file.truncate()
json.dump(config, file, ensure_ascii=False, indent=4)
except json.decoder.JSONDecodeError:
print(f'{realName} 的账户登录态已经过期,已删除该登录态。请重新登录。')
print(f'\033[0;31;40m{id} {realName} 的账户登录态已经过期,已删除该登录态。请重新登录。\033[0m')
with open("config.json", "r+", encoding='utf8') as file:
config = json.load(file)
config['Accounts_login_state'] = []
for i in config['Accounts_login_state']:
if i.get('raw_id') == id:config['Accounts_login_state'].remove(i)
file.seek(0)
file.truncate()
json.dump(config, file, ensure_ascii=False, indent=4)
Expand Down

0 comments on commit 9922cd3

Please sign in to comment.