Skip to content

Instantly share code, notes, and snippets.

@davidschlachter
Last active June 21, 2016 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidschlachter/97e80e6e3881f91b5928005c80fea276 to your computer and use it in GitHub Desktop.
Save davidschlachter/97e80e6e3881f91b5928005c80fea276 to your computer and use it in GitHub Desktop.
Shell script to update timetables for uOttawa schedule generator
#!/bin/bash
#
# Script to update course time tables and restart the schedule generator with the new schedules
#
/bin/su --shell=/bin/bash schedgen <<'EOF'
cd "/etc/schedgen/uOttawa Schedule Generator/course-download"
mv db_activities.csv db_activities.csv.old ; mv db_courses.csv db_courses.csv.old ; mv db_sections.csv db_sections.csv.old
/usr/bin/xvfb-run ./getCourses.py && \
./getTimetables.py -p 8
# Get skipped courses recursively
if [ $? -eq 0 ]; then
OUTPUT0=`./getTimetables.py -s | egrep '^Done work\.'`
OUTPUT1=" "
while [ `echo "$OUTPUT1" | grep -c "$OUTPUT0"` -ne 1 ]; do
OUTPUT1=`./getTimetables.py -s | egrep '^Done work\.'`
echo "Presently OUTPUT0 is $OUTPUT0"
echo "Presently OUTPUT1 is $OUTPUT1"
if [ `echo "$OUTPUT1" | grep -c "$OUTPUT0"` -eq 1 ]; then
break
else
OUTPUT0="$OUTPUT1"
OUTPUT1=" "
fi
echo " "
done
rm *.old
# Remove courses that have no activities
while read -r line; do
if [ `grep -c "$line" db_activities.csv` -eq 0 ]; then
echo "Removing course: $line"
sed "/$line/d" db_courses.csv > tmp && mv tmp db_courses.csv
fi
done < courses.txt
exit 0
else
rm *.csv
mv db_activities.csv.old db_activities.csv; mv db_courses.csv.old db_courses.csv ; mv db_sections.csv.old db_sections.csv
exit 1
fi
EOF
if [ $? -eq 0 ]; then
/bin/systemctl restart schedule-generator
/bin/rm -f /var/www/schl/schedgen/latest.tar.gz /var/www/schl/schedgen/archive/courses-`date +%F`.tar.gz
cd /etc/schedgen/uOttawa\ Schedule\ Generator/course-download && /bin/tar -czf /var/www/schl/schedgen/archive/courses-`date +%F`.tar.gz *.csv *.txt
/bin/ln -s /var/www/schl/schedgen/archive/courses-`date +%F`.tar.gz /var/www/schl/schedgen/latest.tar.gz
else
/bin/echo "Update on `/bin/date` failed" > /var/log/timetables-updater.log
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment