#!/bin/sh

CITY=$1
[ -z "$1" ] && {
	echo "Usage: $0 city"
	exit
}

BASEURL="http://surfin.infotel.bg:2000/wp"

grep '^<A HREF="F_PRINT_REZ' $CITY/* | sed -e "s|.*HREF=\"||;s|\">.*||" | \
while read url ; do
	ST=`echo $url | sed -e "s|.*ST=||;s|&BR.*||"`
	BR=`echo $url | sed -e "s|.*BR=||;s|&CREG.*||"`
	echo "[ -f $CITY/${ST}-${BR}.html ] || curl -A ' ' -o $CITY/${ST}-${BR}.html -f '${BASEURL}/${url}' "
done

