#!/bin/bash
#
# goproblems2sgf.sh by Sylvain Soliman <Sylvain.Soliman@m4x.org>
# Version 0.0.1
#
# extract SGFs form goproblems.com HTML files, and add a meaningful GN
#

if [ ${#*} != 2 -o ! -d $1 -o ! -d $2 ]; then
echo "Usage:" `basename $0` "<input html directory> <output sgf
directory>"
echo " extracts SGFs from HTML files with Genre and Difficulty in
GN"
echo " both directories must already exist"
exit 0
fi

for file in $1/prob*.html
do
genre=`grep -3 "Genre:" $file | tail -1`
diff=`grep -2 "Difficulty:" $file | tail -1 | sed -e 's/<\/\?td>//g'
-e 's/\//-/g'`
begin=`grep -n 'name="sgf"' $file | sed -e 's/:.*$//g'`
tail +$begin $file | sed -e "s/^<\/script>[^(]*(;/(;GN[$genre -
$diff]/g" -e 's/"><\/applet>.*$//g' > $2/`basename $file .html`.sgf
done
