#!/usr/bin/perl -w use strict; sub weekday { my ($day, $month, $year) = @_; if ($month < 3) { $month += 12; --$year; } my $tmp = $day + int((13 * $month - 27)/5) + $year + int($year/4) - int($year/100) + int($year/400); return ($tmp % 7); } my $days_back = shift || 120; my ($start, $end); my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); my @days_month = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); my ($day, $month, $year) = (localtime)[3,4,5]; # Adjust year and month to readable stuff $year += 1900; $month++; $end = sprintf("%d-%02d-%02d", $year,$month,$day); $day -= $days_back; # If we went below 1, then we're into prev month # we while() here for when $days_back is larger than 1 month while ($day < 1) { # Don't forget to pad Feb for leap years if ($month == 3 && ($year % 4) == 0) { $days_month[1]++ } # deceremnt the month and calc the day $day += $days_month[--$month - 1]; if ($month < 1) { $month = 12; $year--; } } $start = sprintf("%d-%02d-%02d", $year,$month,$day); print"$start\n$end\n\n"; system("parsecache -f nlclick -s $start -e $end > nlclick.cache"); system("parsecache -f nlimage -s $start -e $end > nlopen.cache"); #print "$start\n$end\n\n"; for (my $i = 0; $i < $days_back; $i++) { my $wday = weekday($day, $month, $year); if ($wday > 0 && $wday < 6) { my $date = sprintf("%d%02d%02d", $year,$month,$day); #print "$date\n"; $_ = `report pattern --regex='nl=$date' --filter=nlimage --sumonly < nlopen.cache`; my ($opens) = /(.*)/; if (defined($opens)) { $_ = `report pattern --regex='nl=$date' --filter=standard --sumonly < nlclick.cache`; my ($transfers) = /(.*)/; if (!defined($transfers)) { $transfers = 0 } printf("update msnNewsletter set open='%d', click='%d' where dateCreated like '%d-%02d-%02d%%';\n", $opens, $transfers,$year,$month,$day); } } if (++$day > $days_month[$month - 1]) { $day = 1; if (++$month > 12) { $month = 1; $year++; } } } unlink "nlclick.cache"; unlink "nlopen.cache";