#!perl # This is an example of how to control a web-based application using Perl as a scripting language. # It is an unsupported example script. It is intended for educational purposes only and is not # warrantied for any particular purpose - use it at your own risk. # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # Go to ActiveState and download and install the free Perl. This script was used with an older # Perl 5.8 but should work with the latest version. # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! use strict; # Remove any dates from the input url if any so that when the baseline start/end change, the # server will default to using them instead of fixed dates. A real example snippet is # ...&x5=2008-12-01T00:00:00:000&x6=2009-02-28T00:00:00:000... sub stripDates { my $url = shift; my @dates = $url =~ /(&x\d+=\d{4}-\d{2}-\d{2}T[^&]+)/g; foreach my $date (@dates) { $url =~ s/$date//; } return $url; } use Win32::OLE; print "If IE's first tab is stuck on the \"Connecting...\", just click the Homepage Button or navigate to CCC.\n"; # This script will be managing that first tab only, not other tabs in IE! our $ie = Win32::OLE->new("InternetExplorer.Application") || die "Could not start Internet Explorer.\n"; $ie->{visible} = 1; # Set this script up to quit IE if this script is terminated with ^C sub Maybe_Quit_IE { print "Quitting IE because script interrupted by user\n"; $ie->Quit if ($ie); exit(0); } $SIG{'INT'} = 'Maybe_Quit_IE'; # Modify the sleep value below. You should probably should use 300 (5 minutes of seconds). # It is at a low value right now for debugging. If it is too low, IE might redraw # unnecessarily, making it look flashy. If its too high, it will take longer to recognize # user changes to the URL my $secondsToSleep = 8; my $minCCCUrlsNeeded = 3; my $displayedRefreshTimeMsg = 0; my $previousUrl = ""; my @urlsForCCC = (); while (1) # forever { if (@urlsForCCC > 0) { my $doc = $ie->document; unless(defined($doc)) { print "Script quitting because IE has quit.\n"; $ie->Quit; exit(0); } } my $currentUrl = $ie->LocationURL; print "Current URL is unavailable.\n" unless ($currentUrl); print "Current URL is ", ($currentUrl) ? $currentUrl : "", "\n" if ($currentUrl ne $previousUrl); $previousUrl = $currentUrl; if ($currentUrl =~ /\/ccc\//i) { if (@urlsForCCC == 0 || $currentUrl ne $urlsForCCC[0]) { unshift(@urlsForCCC, $currentUrl); print "\nUsing new CCC URL: $urlsForCCC[0]\n"; print "Waiting for another CCC URL.\n" if (@urlsForCCC < $minCCCUrlsNeeded); print "\n"; } } my $nUrls = @urlsForCCC; if ($nUrls >= $minCCCUrlsNeeded) { print "\"Refreshing\" chart by juggling URLs (currently have $nUrls)..."; $ie->Navigate(stripDates($urlsForCCC[-1])); sleep(1); $ie->Navigate(stripDates($urlsForCCC[0])); print "(done refreshing)\n"; print "Using longer refresh time.\n" unless ($displayedRefreshTimeMsg); $displayedRefreshTimeMsg = 1; sleep($secondsToSleep); } else { print "Waiting for user to navigate to CCC URLs (currently have $nUrls, but $minCCCUrlsNeeded are required)\n"; sleep(5); } }