Initial Revision
[ohcount] / test / src_dir / perl1.pl
1 #!/usr/bin/perl
2 # Conserve bandwidth - put a copy of Dilbert on your intranet.
3 # Run every morning with cron - after about 7am Eastern
4 ########################################################
5 use Time::ParseDate;
6 use Time::CTime;
7 use LWP::Simple;
8
9 # Where do you want the image put?
10 $dir="/usr/local/etc/httpd/htdocs/Dilbert";
11 # $dir = "c:/httpd/htdocs/Dilbert";
12 $location ="$dir/dilbert.gif";
13
14 $_ = get("http://www.unitedmedia.com/comics/dilbert/index.html");
15
16 # These next 4 lines will change every time they change the
17 # page layout on the Dilbert site. Check back on my web site
18 # if things suddenly stop working
19 s/^.*strip_left\.gif//s;
20 s/^.*?HREF=\"//s;
21 s/\">.*$//s;
22 $line = "http://www.unitedmedia.com" . $_;
23
24 #  Back up yesterday's image:
25 # get the number
26 open  (ID,"$dir/id");
27 $id=<ID>;
28 close ID;
29
30 $id++;
31 $id=~s/\n$//;
32 `mv $location $dir/dilbert.$id.gif`;
33 # If you're using this on NT, you may want to replace 'mv'
34 # with 'move'.
35
36 open (ID,">$dir/id");
37 print ID "$id";
38 close ID;
39
40 #  Now get the actual image
41 $_ = get($line);
42
43 open (FILE, ">$location");
44 binmode FILE; # Important for NT
45 print FILE;
46 close FILE;
47
48 # Now I want to update the index.html file
49 open (FILE, "$dir/index.html");
50 @index=<FILE>;
51 close FILE;
52
53 $yesterday = parsedate('yesterday');
54 $printdate = strftime('%a, %b %d', localtime($yesterday));
55
56 open (FILE, ">$dir/index.html");
57 for (@index)    {
58 if (/INSERT HERE/)      {
59         print FILE "$_";
60         print FILE "<td><a href=\"dilbert.$id.gif\">$printdate</a></td>\n";
61         if (($id % 5) == 0) {print FILE "</tr><tr>\n"}
62                 }
63 else    {print FILE "$_"};
64         }  #  End for
65 close FILE;
66
67 # Start with an index.html file containing ...
68 # <table border><tr>
69 # <!-- INSERT HERE -->
70 # </tr></table>
71 # ...
72 #  And whatever else you want on the page.