Skip to content
Snippets Groups Projects
Unverified Commit c5224807 authored by Recolic Keghart's avatar Recolic Keghart
Browse files

Upgrade: check if question is answered. Auto mute

parent 7d89f251
No related branches found
No related tags found
No related merge requests found
......@@ -9,18 +9,14 @@ Linux. curl. fish. awk. One mp3 player available on command line.
打开微信 微助教 学生 答题,关闭wifi,按住页面选择在浏览器打开,然后复制下这个页面的url。
编辑d.fish,将url填入set \_url "YourURLHere"。
编辑daemon.fish,将url最后的openid填入set \_openid "YourIDHere"。
./d.fish 它会每5秒检查一次并判断是否需要答题。
./daemon.fish 它会每5秒检查一次并判断是否需要答题。
d.fish使用了gnome的notify-send,kde/其他de用户请根据自己的情况选择修改或删除气泡提醒。
daemon.fish使用了notify-send,其他用户请根据自己的情况选择修改或删除气泡提醒。
d.fish默认使用mpg123/cvlc来播放mp3,其他播放器用户请根据自己情况进行修改。请将电脑声音调大。
daemon.fish默认使用mpg123/cvlc来播放mp3,其他播放器用户请根据自己情况进行修改。请将电脑声音调大。
## Tips
使用./informed.sh来停止一次提醒。
根据经验,url一般会在1-2小时后失效。因此请在课前获取url启动脚本并睡觉。你可以使用juice ssh或超级本在床上完成这一过程。
警惕以下情形: 老师发出一个题,脚本发出警报,你成功答题,老师在第一个题过期之前发出第2个题,你不知道。
badid.mp3 0 → 100644
File added
#!/usr/bin/fish
#Usage: fill _url with url of the page "学生->答题".
#You must `echo "known" > /tmp/gay_known` to tell the script that you've been informed.
set _url 'https://www.teachermate.com.cn/wechat/wechat/guide/answer?openid=0a26740fbf9429d1747f8bc8ff8bf1cb'
set _audio_player "mpg123"
#set _audio_player "cvlc --play-and-exit"
function _is_informed
# May not exist.
if test (cat /tmp/gay_known 2>&1) = "known"
echo "LOG> skipped because informed."
return 0
# ok.
else
echo "LOG> not informed. Launching cvlc."
return 1
end
end
function _on_opened
if _is_informed
return 0
end
eval $_audio_player fire.mp3 > /dev/null 2>&1
notify-send "Warning: Question opened!" "Gay question opened!"
echo "LOG> Detected!"
end
function _on_error
eval $_audio_player error.mp3 > /dev/null 2>&1
notify-send "Warning: Gay cookie invalid!" "Gay cookie expired!"
echo "LOG> Error occurred! Maybe invalid cookie."
end
function _on_notopen
if not test -e /tmp/gay_known
return 0
end
if not rm /tmp/gay_known
echo "WARNING::::::: UNABLE TO REMOVE /tmp/gay_known. Please deal with this programming error immediately!!!!!"
_on_error
end
end
while true
set _status (curl "$_url" 2>/dev/null | awk -f gl.awk)
date
if test "$_status" = "OPENED"
_on_opened
end
if test "$_status" = "UNKNOWN_ERROR"
_on_error
end
if test "$_status" = "NOT_OPENED"
_on_notopen
end
sleep 5
end
#!/usr/bin/fish
#Usage: fill _url with url of the page "学生->答题".
#You must `echo "known" > /tmp/gay_known` to tell the script that you've been informed.
set _openid '593712dbd06b5808e4d4a099e8ad4c8d'
set _url "https://www.teachermate.com.cn/wechat/wechat/guide/answer?openid=$_openid"
set _audio_player "mpg123"
#set _audio_player "cvlc --play-and-exit"
function _check_and_warn
if _all_answered
echo "LOG> exit because all question answered."
return 0
end
eval $_audio_player fire.mp3 > /dev/null 2>&1
notify-send "Warning: Question opened!" "Question opened!"
echo "LOG> Detected!"
end
function _on_unknown_error
eval $_audio_player error.mp3 > /dev/null 2>&1
notify-send "Warning: Error occurred!" "Error occurred!"
echo "LOG> Error occurred!"
end
function _on_openid_error
eval $_audio_player badid.mp3 > /dev/null 2>&1
notify-send "Warning: Invalid openid!" "Error: Invalid openid."
echo "LOG> Invalid openid."
end
set _tmp_path "/tmp/._teachmate_fucker_html"
set awk_urlfilter '
BEGIN {
start = 0
}
{
if (match($0, "以下课堂包含开启的题目")) {
start = 1
}
if (match($0, "以下课堂暂未开启题目") != 0) {
exit
} else if (start == 1) {
print $0
}
}
'
function _all_answered
# This function will return true if no question is opened, so OPENED check is unnecessary.
for class in (cat $_tmp_path | awk $awk_urlfilter | grep 'www.teachermate.com.cn' | sed 's/.*course_id=//g' | sed 's/&open_id=.*//g')
curl --header "openId: $_openid" "https://www.teachermate.com.cn/wechat-api/v1/questions/$class" > $_tmp_path 2>/dev/null
if not grep 'question' $_tmp_path
echo "ERROR> curl wechat-api failed. $class $_openid"
_on_unknown_error
end
if grep '"isAnswered":0' $_tmp_path
# return false
return 1
end
end
# return true
return 0
end
# main loop
while true
date
curl "$_url" > $_tmp_path 2>/dev/null
# network error will be reported by isopen.awk.
set _status (cat $_tmp_path | awk -f isopen.awk)
if test "$_status" = "UNKNOWN_ERROR"
_on_unknown_error
else if test "$_status" = "OPENID_ERROR"
_on_openid_error
else if test "$_status" = "OPENED"
_check_and_warn
end
sleep 5
end
#!/usr/bin/sh
echo "known" > /tmp/known
#!/usr/bin/awk
# Meaning of a: 0-2: check END{}
# 4:
BEGIN {
a = 0
a = 999
}
{
if (match($0, "\"msg\":\"unauthorized\"") != 0) {
a = 999
exit 2
a = 2
exit
}
if (match($0, "以下课堂包含开启的题目") != 0) {
a = 1
exit 1
exit
}
if (match($0, "以下课堂暂未开启题目") != 0) {
a = 1
a = 0
}
if (a == 1 && (match($0, "概率统计-计算机1601-4") != 0)) {
if (a == 1 && (match($0, "single-line\">编号:") != 0)) {
a = 2
exit 0
exit
}
}
END {
if (a == 2) {
if (a == 0) {
print "NOT_OPENED"
exit 0
} else if (a == 1) {
print "OPENED"
exit 1
} else if (a == 2) {
print "OPENID_ERROR"
exit 2
} else {
print "UNKNOWN_ERROR"
exit 2
exit 3
}
}
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