public
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#!/bin/bash -e
 
RIN="6601234567"
PIN="12180"
SIS="sis.rpi.edu"
 
# Options for curl(1), e.g., -vvv for verbose and -s for silent.
CURLOPTS="-s"
 
# Use HTTPS if it's available.
SCHEME=$(if curl -s "https://${SIS}" &>/dev/null; then echo "https"; else echo "http"; fi)
printf "\033[32m[*] Using ${SCHEME}.\033[0m\n" 1>&2
 
# Make a temporary file to store cookies in. If the temporary file contains an
# equals (=) character, it will mess up curl, so generate a new one.
TEMPCOOKIES=$(mktemp -t siscookies.XXXXX)
if [[ "${TEMPCOOKIES}" == *=* ]]; then
rm -f "{TEMPCOOKIES}"
TEMPCOOKIES=$(TMPDIR=/tmp mktemp -t siscookies.XXXXX)
printf "\033[32m[*] Worked around problematic cookie jar filename.\033[0m\n" 1>&2
fi
 
# Log in to SIS
printf "\033[32m[*] Logging in to SIS.\033[0m\n" 1>&2
curl ${CURLOPTS} \
--cookie "TESTID=set" \
--cookie-jar "${TEMPCOOKIES}" \
-F "sid=${RIN}" -F "PIN=${PIN}" \
"${SCHEME}://${SIS}/rss/twbkwbis.P_ValLogin" >/dev/null
 
# Get the terms for which grades are available
printf "\033[32m[*] Looking up most recent semester with available grades.\033[0m\n" 1>&2
SEMESTER=$(
curl ${CURLOPTS} \
--cookie "${TEMPCOOKIES}" \
--cookie-jar "${TEMPCOOKIES}" \
"${SCHEME}://${SIS}/rss/bwskogrd.P_ViewTermGrde" \
| grep -m 1 -Eo "<OPTION VALUE=\"[0-9]+\"" \
| cut -c 16-21
)
printf "\033[32m[*] Found semester ${SEMESTER}.\033[0m\n" 1>&2
 
# Request the grades for this term
curl ${CURLOPTS} \
--cookie "${TEMPCOOKIES}" \
--cookie-jar "${TEMPCOOKIES}" \
-F "term_in=${SEMESTER}" \
"${SCHEME}://${SIS}/rss/bwskogrd.P_ViewGrde" \
| grep -E "^(<TR>|<TD CLASS=\"dddefault\">)" \
| sed '1,21d' \
| sed -n -e :a -e '1,25!{P;N;D;};N;ba' \
| sed -e 's/ *<[^>]*> *//g'
 
# Delete the cookie jar
rm -f "${TEMPCOOKIES}"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.