#!perl -w use strict; use DBI; use LWP::Simple; my $img_url = "http://weather.unisys.com/satellite/sat_ir_west.gif"; my $dbh = DBI->connect( 'dbi:mysql:weather_images', 'user', 'secret', { RaiseError => 1, AutoCommit => 1 } ); my ($min, $hour, $day, $mon, $year) = (localtime())[1..5]; $year += 1900; my $img_name = "$mon-$day-$year-$hour:$min"; my $img_data = get($img_url); die("failed to fetch image from internet!\n") unless ( defined($img_data) ); # fetch the last row we added to the table my $latest_entry = $dbh->selectrow_arrayref( 'SELECT image_file FROM gw_ir ORDER BY image_id DESC LIMIT 1' ); # either no data in database or the file contents # have changed since the last update if (not defined($latest_entry) or $latest_entry->[0] ne $img_data) { $dbh->do( 'INSERT INTO gw_ir (image_name, image_file) VALUES(?,?)', undef, $img_name, $img_data ); warn("File was not current; updates made.\n"); } else { warn("File was current, no updates made.\n"); } $dbh->disconnect();