Skip to content
Snippets Groups Projects
Verified Commit 9e54fd6b authored by Recolic Keghart's avatar Recolic Keghart
Browse files

IMPORTANT BUG FIX: TEACHERMATE API UPDATE

parent 30225d53
No related branches found
No related tags found
No related merge requests found
Pipeline #167 passed with stage
in 1 minute and 19 seconds
...@@ -24,9 +24,17 @@ def teachermate_daemon(): ...@@ -24,9 +24,17 @@ def teachermate_daemon():
for prof in profiles: for prof in profiles:
if prof.cookiefl == '': if prof.cookiefl == '':
continue continue
ret = subprocess.call(['./signin-once.fish', prof.openid, prof.N, prof.E, prof.cookiefl]) # subprocess.call is outdated. Now I'm using everything in docker so I won't support python<3.5 anymore
# ret = subprocess.call(['./signin-once.fish', prof.openid, prof.N, prof.E, prof.cookiefl])
completed = subprocess.run(['./signin-once.fish', prof.openid, prof.N, prof.E, prof.cookiefl], stdout=subprocess.PIPE)
ret = completed.return_code
if ret == 0: if ret == 0:
prof.status_string += '\nSuccessed at ' + str(datetime.datetime.now()) stdout = completed.stdout.decode('utf-8').strip()
def findStudentRankFromStdout(s):
# {"signRank":34,"studentRank":1}
pos = s.find('studentRank')
return -1 if pos == -1 else int(s[pos+13:-1])
prof.status_string += '\nSuccessed at {}, You\'re the {}th student to signin!'.format(str(datetime.datetime.now()), findStudentRankFromStdout(stdout))
elif ret == 1: elif ret == 1:
prof.status_string += '\nFailed to signin at ' + str(datetime.datetime.now()) prof.status_string += '\nFailed to signin at ' + str(datetime.datetime.now())
elif ret == 2: elif ret == 2:
......
...@@ -22,12 +22,17 @@ function try_signin_once --description "signin_once <openid> <N> <E> <tmpfl> <co ...@@ -22,12 +22,17 @@ function try_signin_once --description "signin_once <openid> <N> <E> <tmpfl> <co
end end
if grep -F '签到中...' $tmpfl > /dev/null if grep -F '签到中...' $tmpfl > /dev/null
################## Real signin!!! ################## Real signin!!!
set _courseid (curl "$_url" -v 2>&1 | grep '^< Location: ' | sed 's/^.*course_id=//') # set _courseid (curl "$_url" -v 2>&1 | grep '^< Location: ' | sed 's/^.*course_id=//')
set _wx_csrf (grep 'Set-Cookie' $cookiefl | sed 's/^.*wx_csrf_cookie=//' | sed 's/;.*$//') set _courseid (cat "$tmpfl" | grep 'id="course-id' | sed 's/^.*value="//g' | sed 's/" .*$//g')
curl "https://www.teachermate.com.cn/wechat-api/v1/class-attendance/student-sign-in" --data "openid=$_openid&course_id=$_courseid&lon=$_EastLongitude&lat=$_NorthLatitude&wx_csrf_name=$_wx_csrf" > $cookiefl 2>/dev/null set _signid (cat "$tmpfl" | grep 'id="sign-id' | sed 's/^.*value="//g' | sed 's/" .*$//g')
# set _wx_csrf (grep 'Set-Cookie' $cookiefl | sed 's/^.*wx_csrf_cookie=//' | sed 's/;.*$//')
set _wx_csrf (cat "$tmpfl" | grep 'id="token-hash' | sed 's/^.*value="//g' | sed 's/" .*$//g')
# recolic: they changed `www.teachermate.com.cn` to `v18.teachermate.com.cn` but doesn't provide new certificate... I added -k here. (which indicates that their client (wechat and dingtalk) doesn't check certificate at all)
curl -k "https://v18.teachermate.com.cn/wechat-api/v1/class-attendance/student-sign-in" --data "openid=$_openid&courseId=$_courseid&lon=$_EastLongitude&lat=$_NorthLatitude&signId=$_signid&wx_csrf_name=$_wx_csrf" > $cookiefl 2>/dev/null
grep -F 'repeat sign in' $cookiefl > /dev/null; and return $result_nothing grep -F 'repeat sign in' $cookiefl > /dev/null; and return $result_nothing
grep -F '":["OK",' $cookiefl > /dev/null; and return $result_success; or return $result_failed # print the signRank if success
################## grep -F 'signRank' $cookiefl; and return $result_success; or return $result_failed
################## Real signin end!!!
end end
if grep -F "<p class='success-tip'>暂无开启的签到" $tmpfl > /dev/null if grep -F "<p class='success-tip'>暂无开启的签到" $tmpfl > /dev/null
return $result_nothing return $result_nothing
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment