Created
May 14, 2011 04:58
-
-
Save rgov/971934 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment