#!/bin/sh -x
F=scan-1999-10-24.csv
SF="ship/sipb-library.html"

cat > $SF <<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
  <head>
    <meta name="generator" content="thokbook">
    <title>SIPB Office Library</title>
  </head>
  <body>
    <h1>SIPB Office Library</h1>
    <p>These are some of the books available around the SIPB office in W20.
       It is not complete, but is at least a
       place to look before buying new ones.</p>
EOF
for i in $(awk -F, '/sipb/ { print $3 }' < $F | grep -v '"NR"'); do
  ISBN=$(eval echo $i)
  echo "$ISBN"
  # cookone $ISBN
  if [ -s "rawmarc/${ISBN}.marc" ]; then
    perl slurprecord.pl $ISBN
    cp "cookmarc/${ISBN}-full.html" "ship/marc${ISBN}.html"
  fi
done
awk -F, '/sipb/ && !/"NR"/ { shelf[$2]++; } END { for (i in shelf) { print i }; }' < $F | grep -v 'sipb cd' | sort | while read x; do 
    SCT=$(eval echo $x)
cat >> $SF <<EOF
    <h2>$SCT</h2>
    <ul>
EOF
for i in $(awk -F, "/$SCT/"' { print $3 }' < $F | grep -v '"NR"'); do
  ISBN=$(eval echo $i)
  echo "$ISBN"
  if [ -s "rawmarc/${ISBN}.marc" ]; then
    cat cookmarc/${ISBN}-frag.html >> $SF
  fi
done
cat >> $SF <<EOF
    </ul>
EOF
done

cat >> $SF <<EOF
  </body>
</html>
EOF
