Skip to content

Instantly share code, notes, and snippets.

@LeeYunhang
Created June 7, 2017 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeeYunhang/69f004c7d7cf29f392be2b7f6a880359 to your computer and use it in GitHub Desktop.
Save LeeYunhang/69f004c7d7cf29f392be2b7f6a880359 to your computer and use it in GitHub Desktop.
cqut-score
#! /bin/bash
version=1.0.0
# ------------------ input ---------------------
if [ "$#" == '1' ]; then
if [ "$1" == '--help' ] || [ "$1" == '-h' ]; then
cat <<<"
usage: cqut-score [OPTION] ... \n
a command-line tool was used for query your score in CQUT's website.
-h, --help show this help message and exit
-a, NO your student id
-p, PASSWORD your password
-c, CONFIG_FILE path to config file. default at HOME/.cqut-score
-v, --version check version
example:
cqut-score -a account -p password
or
cqut-score -a account
or
cqut-score -c config_file_path
configuration file format:
no <your account>
passwd <your password>
-------------------------------------------------------
auther: mrcode, mrcodehang@outlook.com
my website: https://mrcodex.com"
exit
elif [ "$1" == '-v' ] || [ "$1" == '--version' ]; then
echo $version
exit
else
echo "Invalid format!"
exit 1
fi
elif [ "$#" == '2' ]; then
if [ $1 == '-c' ]; then
if [ ! -f $2 ]; then
echo "File does not exists."
fi
config=`cat $2 | cut -d" " -f2`
read account password <<< `echo $config`
elif [ $1 == '-a' ]; then
account=$2
read -p "Please enter your password:" -s password
fi
elif [ $# == '4' ]; then
let count=0
until [ $count -ge 4 ]; do
read -d" " option
if [ $option == '-a' ]; then
read -d" " account
elif [ $option == '-p' ]; then
read -d" " password
fi
let count+=2
done <<< $@
elif [ $# == '0' ]; then
if [ ! -f $HOME/.cqut-score ]; then
echo "Can not found default configuration file"
exit 1
fi
config=`cat $HOME/.cqut-score | cut -d" " -f2`
read account password <<< `echo $config`
fi
tempdir="/tmp/cqut/core"
login="${tempdir}/login"
userAegent="User-Agent: Mozilla/5.0 (X11; Lin ux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36"
jwxtHost='http://jwxt.i.cqut.edu.cn'
man_url='http://i.cqut.edu.cn'
is_dev=0 # is develop mode
if [ ! -d /tmp/cqut-core ]; then
mkdir -p $tempdir
fi
curl -si http://i.cqut.edu.cn/zfca/login?service=http%3A%2F%2Fi.cqut.edu.cn%2Fportal.do > $login
cookie=`cat $login | egrep "^Set-Cookie" | cut -d: -f2 | cut -c 13-44`
lt=`cat $login | egrep "name=\"lt\"" | cut -d"\"" -f6`
result=`curl -si -H "Content-Type: application/x-www-form-urlencoded" -d "useValidateCode=0&isremenberme=0&username=${account}&password=${password}&losetime=30&lt=${lt}&submit1= &ip=&_eventId=submit" -X POST "http://i.cqut.edu.cn/zfca/login?service=http%3A%2F%2Fi.cqut.edu.cn%2Fportal.do" --cookie "JSESSIONID=${cookie}" `
location=`echo "$result" | egrep "^Location" | xargs -I{} expr substr {} 10 1000`
cookie1=`echo "$result" | egrep "^Set-Cookie: CAST" | cut -c 20-85`
ticket=`echo $location | cut -d= -f2`
[ $is_dev -eq 1 ] && echo ticket: $ticket
tmp1=`curl --cookie "JSESSIONID=${cookie};CASTGC=${cookie1}" -si "http://i.cqut.edu.cn/zfca/login?yhlx=student&login=0122579031373493728&url=xs_main_aspx"`
[ $is_dev -eq 1 ] && echo "$tmp1"
verify=`echo "$tmp1" | egrep '^Location' | cut -d: -f3 | egrep "verify=[a-zA-Z0-9]+\b" -o | cut -d= -f2`
location=`echo "$tmp1" | egrep "^Location" | cut -d: -f2-`
read jwxt_url querystring <<< ${location/\?/\ }
tmp2=`curl -si -G --data-urlencode "${querystring}" ${jwxt_url}` # this response will set cookie
[ $is_dev -eq 1 ] && echo tmp2 "$tmp2"
location=`echo "$tmp2" | egrep "^Location" | cut -d: -f 2-`
location=${location/\ /}
cookie2=`echo "$tmp2" | egrep "^Set" | cut -d: -f2- | cut -d";" -f1`
url=`echo ${jwxtHost}"$location" | sed 's/%3D/=/g; s/%26/\&/g; s/%3A/:/g'`
url=${url:0:-4}
[ $is_dev -eq 1 ] && echo url: $url
[ $is_dev -eq 1 ] && echo $cookie2
tmp3=$(curl -si "${url}" --cookie "$cookie2")
location=`echo "$tmp3" | egrep "^Location" | cut -d: -f 2-`
key=${location:2:26}
url="http://jwxt.i.cqut.edu.cn/${key}/xs_main.aspx?xh=${account}&type=1"
tmp4=`curl -si ${url} --cookie "$cookie2" -H "$userAegent"`
[ $is_dev -eq 1 ] && echo referer: ${man_url}/portal.do?ticket=${ticket}
url="${jwxtHost}/${key}/xscjcx_dq.aspx?xh=${account}&xm=%C0%EE%D4%C6%BA%BD&gnmkdm=N121607"
tmp5=`curl -si ${url} --cookie "$cookie2" -H "$userAegent" | iconv -f gb2312 -t utf-8 | sed '116,$s/<[^>]*>/!/g; 1,115d' | cut -d"!" -f2,4,6,8,14,24 | tr '!' ' '`
[ $is_dev -eq 1 ] && echo "$tmp5"
no="学号:${account}"
name=`echo "$tmp5" | sed '1s/<[^>]*>//g'`
# echo $name
printf "\n\n\t%-10s %-5s %-6s %-7s %-6s \t%s\n\n" "Year" "Term" "Code" "Credit" "Score" "Name"
while read year term code name credit score; do
printf "\t%-10s %-5s %-6s %-7s %-6s \t%s\n" "$year" "$term" "$code" "$credit" "$score" "$name"
done <<< "$tmp5"
@holocc
Copy link

holocc commented Sep 26, 2017

good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment