changeset 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 055c33cba66e
children bf7a9f63bd82
files update.sh
diffstat 1 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/update.sh	Tue Feb 05 11:18:34 2013 +0200
+++ b/update.sh	Fri Feb 15 20:13:20 2013 +0200
@@ -8,6 +8,21 @@
 fi
 }
 
+function fetch()
+{
+URLPREFIX="$1"
+CLASSFILE="$2"
+LISTFILE="$2.tmp"
+PATPREFIX="$3"
+
+if wget -q -O "$LISTFILE" "$URLPREFIX"; then
+	perl -ne "if (/<a href=\"${PATPREFIX}([A-Z]{3}\d\S+)${URLSUFFIX}\">/) { print \"\$1\n\"; }" < "$LISTFILE" > "$CLASSFILE"
+	echo -n "* Fetched classfile $CLASSFILE: "
+	cat "$CLASSFILE" | wc -l
+fi
+}
+
+
 function parse()
 {
 # Create cache directories, if they do not exist
@@ -17,17 +32,10 @@
 
 URLPREFIX="$1"
 CLASSFILE="$2"
-LISTFILE="$2.tmp"
 PATPREFIX="$3"
 
 echo "<? \$origBaseURI = \"${URLPREFIX}${PATPREFIX}\"; \$origBaseExt = \".htm\"; ?>" > "${CACHEDIR}baseuri.data";
 
-if wget -q -O "$LISTFILE" "$URLPREFIX"; then
-	perl -ne "if (/<a href=\"${PATPREFIX}([A-Z]{3}\d\S+)${URLSUFFIX}\">/) { print \"\$1\n\"; }" < "$LISTFILE" > "$CLASSFILE"
-	echo -n "* Fetched classfile $CLASSFILE: "
-	cat "$CLASSFILE" | wc -l
-fi
-
 if test -e "$CLASSFILE"; then
 echo "* Processing $CLASSFILE ..."
 cat "$CLASSFILE" | while read i; do
@@ -79,8 +87,9 @@
 chmod 751 . && chmod 644 *.php *.css && chmod 600 coursecache.txt classes.txt classes_next.txt
 
 CACHEDIR="cache/"
+fetch "http://www.oamk.fi/tyojarjestykset/otek/luokat/" "classes.txt" "OR_"
+fetch "http://www.oamk.fi/~heikkim/riihi3/Luokat/" "classes.txt" "Ryh._"
 parse "http://www.oamk.fi/tyojarjestykset/otek/luokat/" "classes.txt" "OR_"
-#parse "http://www.oamk.fi/~heikkim/riihi2/Oppilaat/" "classes.txt" "Ryh._"
 
 CACHEDIR="cache-next/"
-parse "http://www.oamk.fi/~heikkim/riihi3/Luokat/" "classes_next.txt" "Ryh._"
+parse "http://www.oamk.fi/~heikkim/riihi4/luokat/" "classes_next.txt" "Ryh._"