#!/usr/bin/perl -w

# Contact info:
#    bhepple@freeshell.org
#    http://sedumi.freeshell.org
#    
# Version 1.0
#
# Copyright (C) 2002 Bob Hepple
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.

my $watchpageDir = "$ENV{HOME}/.watchpage";

# change the URLs to suit yourself. Format for each entry is:
# "label", - anything you like but must be unique and will be used as the filename
# to store the page in ~/.watchpage
# {
# TITLE => "human readable title".
# URL => "http://.... etc"
# },

my %url = 
  (
   "pocket", 
   {
    TITLE => "Psion Pocketinfo",
    URL  => "http://3lib.ukonline.co.uk/pocketinfo/index.html"
   },

   "fvwm",
   {
    TITLE => "The Official FVWM Homepage - NEWS Information",
    URL  => "http://www.fvwm.org/generated/NEWS.html"
   },

   "wxDesigner",
   {
    TITLE => "wxDesigner",
    URL  => "http://www.roebling.de/news.html"
   },

   "wxWorkshop",
   {
    TITLE => "wxWorkshop",
    URL  => "http://wxworkshop.sourceforge.net/download.htm"
   },

   "mouse",
   {
    TITLE => "Scrolling Mouse For X",
    URL  => "http://koala.ilog.fr/colas/mouse-wheel-scroll"
   },

   "sane",
   {
    TITLE => "SANE Scanner",
    URL => "http://www.mostang.com/sane/sane-backends.html"
   },

   "xemacs",
   {
    TITLE => "XEmacs",
    URL => "http://www.xemacs.org"
   },
  );

if (! -d "$watchpageDir") {
  mkdir "$watchpageDir",755;
}
chdir $watchpageDir;

while (($name, $record) = each %url) {
  $oldfile = $name;
  $newfile = $name . ".new";
  $errorFile = "error";

  #print "Fetching $name: $record->{TITLE}\n";
  unlink $errorFile;
  system("lynx -error_file=$errorFile -dump $record->{URL} >$newfile 2>/dev/null\n");

  if (!system("grep -i '^STATUS=.*error' $errorFile >/dev/null 2>&1")) {
    print "Error on: $record->{TITLE}: $record->{URL}: ";
    system("grep -i '^STATUS=.*error' $errorFile");
    print "\n";
  } else {
    if (system("diff -b $oldfile $newfile >/dev/null 2>&1")) {
      print "Changes at: $record->{TITLE}: $record->{URL}\n\n";
    }
    rename $newfile,$oldfile;
  }
}