-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcatenotes
More file actions
executable file
·44 lines (36 loc) · 2.17 KB
/
catenotes
File metadata and controls
executable file
·44 lines (36 loc) · 2.17 KB
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
#!/bin/bash
# Shell script for downloading all notes from CATE.
read -p "Enter the year when the current academic year started, e.g. '2011': " year
read -p "Enter the course code for your course, e.g. 'c2': " ccode
read -p "Where would you like to store these files? (CATE-$year-$ccode): " cate_dir
read -p "Enter your DoC username: " username
read -s -p "Enter your DoC password: " password
if [ -z "$cate_dir" ]; then
cate_dir="CATE-$year-$ccode"
fi
echo -e "\nDownloading notes from CATE..."
curl https://$username:$password@cate.doc.ic.ac.uk/timetable.cgi?keyt=$year:{1,3,5}:$ccode:$username -s | grep -e \
"<td rowspan=\"[0-9]\" bgcolor=\"white\"><b><font color=\"blue\">[0-9]*</font>[-a-zA-Z0-9 ]*</b><br>" -A2 | sed "s/--//g" | sed 's/^[ \t]*//' | awk NF > .clist
grep .clist -e "<td" | awk '{print $4 $5 $6 $7}' | sed 's/color=\"blue\">\([0-9]*\)<\/font>\([a-zA-Z^<]*\)/\1\2/' | sed 's/<\/b><br>//' | sed 's/<img.*//' > .flist
mkdir $cate_dir 2> /dev/null
cat .flist | while read line; do
mkdir $cate_dir/$line 2> /dev/null
code=`echo $line | cut -f1 -d'-'`
echo "Downloading notes for $line..."
notescode=`grep .clist -e $code -A1 | grep "<a" | sed 's/<a href=\"notes.cgi?key='$year':\([0-9]*\):[0-9]*:'$ccode':new:'$username'\">/\1/' | head -n1`
noteslist=`curl https://$username:$password@cate.doc.ic.ac.uk/notes.cgi?key=$year:$notescode:3:$ccode:new:$username -s | grep -e "<a href=\"showfile.cgi" \
| sed "s/<td bgcolor=\"white\"><a href=\"showfile.cgi?key=$year:3:\([0-9]*\):$ccode:NOTES:$username\"/\1/" | cut -f1 -d'>'`
index=1
for i in $noteslist
do
name=`curl https://$username:$password@cate.doc.ic.ac.uk/notes.cgi?key=$year:$notescode:3:$ccode:new:$username -s | grep -e "<a href=\"showfile.cgi?key=$year:3:$i" \
| sed "s/<td bgcolor=\"white\"><a href=\"showfile.cgi?key=$year:3:\([0-9]*\):$ccode:NOTES:$username\"/\1/" | cut -f2 -d'>' | cut -f1 -d'<'`
echo "Downloading $name..."
curl https://$username:$password@cate.doc.ic.ac.uk/showfile.cgi?key=$year:3:$i:$ccode:NOTES:$username -s -o "$cate_dir/$line/$index-$name.pdf"
index=`expr $index + 1`
done
index=`expr $index - 1`
echo "$index items downloaded into $line."
done
rm .clist
rm .flist