#!/bin/sh -
PATH=$PATH:/l/palm/bin; export PATH

site=http://arborweb.com
url=$site/calendar/nightspots/date/
urls=`perl -e '$t = time;
    foreach (reverse 0 .. 3) { &pr($t + 86400 * $_) }
    sub pr { ($y, $m, $d) = (localtime($_[0]))[5,4,3]; $y += 1900; $m++;
	     printf "%s%04d%02d%02d.html\n", "'"$url"'", $y, $m, $d; }'`

title='Nightspots Calendar'
dest="${PALMINST-$HOME/l/palm/install}/nightcal.pdb"

# clipnights - personalized Palm web clipper for local nightspot shows
# Steve Kinzler, steve@kinzler.com, Aug 01
# https://kinzler.com/me/home.html#palm

case "$1" in
-h)	echo "usage: $0 [ [ -o ] mailaddr ... ]" 1>&2; exit 1;;
esac

tmpA=/tmp/cnA$$.html
tmpB=/tmp/cnB$$
trap "rm -f $tmpA $tmpB; exit" 0 1 2 13 15

for url in $urls
do
	lynx -source "$url"
done > $tmpA
grep '^lynx: ' $tmpA && exit $?

case "$#" in
0)	;;
*)	exit=
	case "$1" in
	-o)	exit="$1"; shift;;
	esac
	lynx -dump $tmpA | perl -pe "s,file://localhost,$site,g" |
		mail -s "$title" "$@"
	case "$exit" in
	?*)	exit;;
	esac;;
esac

html2pdbtxt -t"$title" $tmpA > $tmpB

txt2pdbdoc "$title" $tmpB "$dest"
