comparison update.sh @ 101:891bd3c93f96

Modularize update script and fetch list of classes data separately from the actual class data.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 15 Feb 2013 20:13:20 +0200
parents acb600abc0c7
children bf7a9f63bd82
comparison
equal deleted inserted replaced
100:055c33cba66e 101:891bd3c93f96
6 if test ! -d "$1"; then 6 if test ! -d "$1"; then
7 mkdir -p "$1" && chmod 751 "$1" 7 mkdir -p "$1" && chmod 751 "$1"
8 fi 8 fi
9 } 9 }
10 10
11 function fetch()
12 {
13 URLPREFIX="$1"
14 CLASSFILE="$2"
15 LISTFILE="$2.tmp"
16 PATPREFIX="$3"
17
18 if wget -q -O "$LISTFILE" "$URLPREFIX"; then
19 perl -ne "if (/<a href=\"${PATPREFIX}([A-Z]{3}\d\S+)${URLSUFFIX}\">/) { print \"\$1\n\"; }" < "$LISTFILE" > "$CLASSFILE"
20 echo -n "* Fetched classfile $CLASSFILE: "
21 cat "$CLASSFILE" | wc -l
22 fi
23 }
24
25
11 function parse() 26 function parse()
12 { 27 {
13 # Create cache directories, if they do not exist 28 # Create cache directories, if they do not exist
14 OLDCACHEDIR="${CACHEDIR}old/" 29 OLDCACHEDIR="${CACHEDIR}old/"
15 createdir "${OLDCACHEDIR}" 30 createdir "${OLDCACHEDIR}"
16 createdir "${CACHEDIR}" 31 createdir "${CACHEDIR}"
17 32
18 URLPREFIX="$1" 33 URLPREFIX="$1"
19 CLASSFILE="$2" 34 CLASSFILE="$2"
20 LISTFILE="$2.tmp"
21 PATPREFIX="$3" 35 PATPREFIX="$3"
22 36
23 echo "<? \$origBaseURI = \"${URLPREFIX}${PATPREFIX}\"; \$origBaseExt = \".htm\"; ?>" > "${CACHEDIR}baseuri.data"; 37 echo "<? \$origBaseURI = \"${URLPREFIX}${PATPREFIX}\"; \$origBaseExt = \".htm\"; ?>" > "${CACHEDIR}baseuri.data";
24
25 if wget -q -O "$LISTFILE" "$URLPREFIX"; then
26 perl -ne "if (/<a href=\"${PATPREFIX}([A-Z]{3}\d\S+)${URLSUFFIX}\">/) { print \"\$1\n\"; }" < "$LISTFILE" > "$CLASSFILE"
27 echo -n "* Fetched classfile $CLASSFILE: "
28 cat "$CLASSFILE" | wc -l
29 fi
30 38
31 if test -e "$CLASSFILE"; then 39 if test -e "$CLASSFILE"; then
32 echo "* Processing $CLASSFILE ..." 40 echo "* Processing $CLASSFILE ..."
33 cat "$CLASSFILE" | while read i; do 41 cat "$CLASSFILE" | while read i; do
34 parse=no 42 parse=no
77 85
78 # Fix permissions 86 # Fix permissions
79 chmod 751 . && chmod 644 *.php *.css && chmod 600 coursecache.txt classes.txt classes_next.txt 87 chmod 751 . && chmod 644 *.php *.css && chmod 600 coursecache.txt classes.txt classes_next.txt
80 88
81 CACHEDIR="cache/" 89 CACHEDIR="cache/"
90 fetch "http://www.oamk.fi/tyojarjestykset/otek/luokat/" "classes.txt" "OR_"
91 fetch "http://www.oamk.fi/~heikkim/riihi3/Luokat/" "classes.txt" "Ryh._"
82 parse "http://www.oamk.fi/tyojarjestykset/otek/luokat/" "classes.txt" "OR_" 92 parse "http://www.oamk.fi/tyojarjestykset/otek/luokat/" "classes.txt" "OR_"
83 #parse "http://www.oamk.fi/~heikkim/riihi2/Oppilaat/" "classes.txt" "Ryh._"
84 93
85 CACHEDIR="cache-next/" 94 CACHEDIR="cache-next/"
86 parse "http://www.oamk.fi/~heikkim/riihi3/Luokat/" "classes_next.txt" "Ryh._" 95 parse "http://www.oamk.fi/~heikkim/riihi4/luokat/" "classes_next.txt" "Ryh._"