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