from
asyncio.windows_events
import
NULL
import
requests
import
json
import
time
import
os
import
random
from
lxml
import
etree
import
sys
name
=
""
passwd
=
""
itime
=
"4"
token
=
''
okcookie
=
{}
uid
=
''
classini
=
[]
headers
=
{
'User-Agent'
:
'Dalvik/2.1.0 (Linux; U; Android 11; M2007J3SC Build/RKQ1.200826.002) (device:M2007J3SC) Language/zh_CN com.chaoxing.mobile/ChaoXingStudy_3_5.1.3_android_phone_613_74 '
}
def
login():
print
(
"登录模块启动"
)
data
=
{
'uname'
: name,
'code'
: passwd,
'loginType'
:
'1'
,
'roleSelect'
:
'true'
}
r
=
requests.post(
'https://passport2-api.chaoxing.com/v11/loginregister'
, headers
=
headers, data
=
data)
load_cookies
=
requests.utils.dict_from_cookiejar(r.cookies)
fo
=
open
(
"cookie.txt"
,
"w"
)
fo.write(
str
(json.dumps(load_cookies)))
print
(
"cookie保存成功"
)
fo.close()
print
(
"重启程序"
)
restart_program()
def
cookie_check():
if
os.path.exists(
"cookie.txt"
)
=
=
True
:
f
=
open
(
'cookie.txt'
,
'r'
,encoding
=
"utf-8"
)
dic
=
json.loads(f.read())
response
=
requests.get(
'https://mooc1-api.chaoxing.com/mycourse/backclazzdata'
, headers
=
headers,cookies
=
dic)
if
'成功'
in
response.text:
return
[
True
,dic,dic[
'UID'
]]
else
:
print
(
"cookie好像失效了,启动重新获取"
)
login()
else
:
print
(
"未找到cookie文件呀启动登录"
)
login()
def
get_class():
r
=
requests.get(
'https://mooc1-api.chaoxing.com/mycourse/backclazzdata?view=json&mcode='
, headers
=
headers, cookies
=
okcookie)
classinfo
=
json.loads(r.text)
for
i
in
classinfo[
'channelList'
]:
if
"course"
not
in
str
(i):
continue
if
str
(
"-1"
)
in
str
(i[
"cfid"
]):
classini.append([i[
'content'
][
'course'
][
'data'
][
0
][
'name'
],i[
'content'
][
'course'
][
'data'
][
0
][
'id'
],i[
'key'
]])
print
(
"\n\n"
+
"*"
*
5
+
"课程获取成功"
+
"*"
*
5
+
"\n\n"
)
def
sign(
id
):
response
=
requests.get(
'https://mobilelearn.chaoxing.com/pptSign/stuSignajax?activeId='
+
str
(
id
)
+
'&uid='
+
uid, headers
=
headers,cookies
=
okcookie)
if
'succ'
in
response.text:
print
(
"\n\n"
+
"*"
*
5
+
"成功"
+
"*"
*
5
+
"\n\n"
)
if
token
=
=
NULL:
return
response
=
requests.get(
"https://www.pushplus.plus/send?token="
+
token
+
"&title="
+
str
(random.randint(
0
,
100
))
+
"您的学习通&content=成功签到"
)
print
(response.text)
def
get_active_one():
for
i
in
classini:
print
(
"查询"
+
i[
0
]
+
"...."
)
r
=
requests.get(
'https://mobilelearn.chaoxing.com/ppt/activeAPI/taskactivelist?courseId='
+
str
(i[
1
])
+
'&classId='
+
str
(i[
2
]), headers
=
headers, cookies
=
okcookie)
a
=
json.loads(r.text)
if
str
(
"频繁"
)
in
str
(a):
print
(
"\n\n\n出现频繁自动跳转备用接口\n\n\n"
)
get_active_two()
break
if
str
(
"进行中(0)"
)
in
str
(a[
"groupList"
][
0
][
'name'
]):
print
(
"无活动跳过\n"
)
continue
for
o
in
a[
'activeList'
]:
if
str
(
"1"
)
not
in
str
(o[
"status"
]):
print
(
"不是进行中的跳过\n"
)
continue
if
str
(
"2"
)
not
in
str
(o[
"activeType"
]):
print
(
"不是进行中的签到任务\n"
)
continue
sign(o[
"id"
])
time.sleep(random.randint(
2
,
10
))
def
get_active_two():
for
i
in
classini:
print
(
"查询"
+
i[
0
]
+
"...."
)
r
=
requests.get(
'https://mobilelearn.chaoxing.com/widget/pcpick/stu/index?courseId='
+
str
(i[
1
])
+
'&jclassId='
+
str
(i[
2
]), headers
=
headers, cookies
=
okcookie)
if
str
(
"频繁"
)
in
r.text:
print
(
"\n\n\n出现频繁\n\n\n"
)
return
html
=
etree.HTML(r.text)
act
=
html.xpath(
'//*[@id="startList"]/div/div/@onclick'
)
if
len
(act)
=
=
0
:
print
(
"无活动跳过\n"
)
continue
if
str
(
",2,"
)
not
in
str
(act):
print
(
"不是进行中的签到任务\n"
)
continue
for
i
in
act:
go
=
i
go
=
go.replace(
'activeDetail('
,'')
go
=
go.replace(
',2,null)'
,'')
sign(go)
time.sleep(random.randint(
2
,
10
))
def
restart_program():
python
=
sys.executable
os.execl(python, python,
*
sys.argv)
if
__name__
=
=
'__main__'
:
if
cookie_check()[
0
]
=
=
True
:
print
(
"cookie检测成功"
)
okcookie
=
cookie_check()[
1
]
uid
=
cookie_check()[
2
]
print
(
"进入课程获取"
)
get_class()
get_active_one()