#checkdone
use strict;


my $donedir="E:\\chartsweep\\done";
opendir(DIR,$donedir);
my @donefiles=readdir(DIR);
closedir(DIR);

sub monthtonum
{
	my $word=shift;
	if ($word eq "January") {return "01";}
	if ($word eq "February") {return "02";}
	if ($word eq "March") {return "03";}
	if ($word eq "April") {return "04";}
	if ($word eq "May") {return "05";}
	if ($word eq "June") {return "06";}
	if ($word eq "July") {return "07";}
	if ($word eq "August") {return "08";}
	if ($word eq "September") {return "09";}
	if ($word eq "October") {return "10";}
	if ($word eq "November") {return "11";}
	if ($word eq "December") {return "12";}
}

my @goodfiles=();
#print "@donefiles";
foreach my $file (@donefiles)
{
	if ($file =~ /[0-9]{8}.*\.mp3/i)
	{
		push(@goodfiles,$file);
	}
}


my $longass='AAA';

foreach my $file (@goodfiles)
{
	#print "working on $file\n";
	#print "trying $file\n";
	$file =~ /^([0-9]{4})([0-9]{2})([0-9]{2})/;
	my $year=$1;
	my $month=$2;
	my $day=$3;
	$longass.="AAA"."$year"."$month"."$day";
	#print "got song for $year $month $day\n";
}

#print "longass is \n$longass\n\n";
my $tocheck="C:\\projects\\chartsweep90s\\all\.htm";
open UPDATE,"< $tocheck";
my @lines=<UPDATE>;
close UPDATE;

my $out="C:\\projects\\chartsweep90s\\outt\.htm";
open OUT,"> $out";
print "writing to $out\n";


my $curyear=1800;
my $remaining=0;
my $totalsongcount=0;
my %missedthisyear=();
foreach my $line (@lines)
{
	#print "\nline is $line";
	if ($line =~ /([0-9]{4})/)
	{
		print OUT "\<tr\>\<td\>$missedthisyear{$curyear} missing\n\<tr\>\<td\>\&nbsp;" if ($curyear != 1800);
		$curyear=$1;
		$missedthisyear{$curyear}=0;
		print "curyear set to $curyear\n";
		print OUT "$line";
	}
	elsif ($line =~ / [0-9]/)
	{
		$totalsongcount++;
		#print "line has a number.\n";
		$line =~ s/\n//;
		$line =~ s/\<tr\>//g;
		#print "line is now $line\n";
		my @splitline=split(/\<td\>/,$line);
		my $date=$splitline[1];
		my $song=$splitline[2];
		my $artist=$splitline[3];
		my $stars=$splitline[4];
		#print "date song artist stars: $date   $song   $artist $stars\n";
		$date =~ /^([A-Z][a-z]*)\s([0-9]{1,2})/;
		my $month=$1;
		my $day=$2;
		
				
		if ($day<10) {$day="0".$day;}

		#print "year is $curyear month is $month, day is $day, monthtonum is ".monthtonum($month)."\n";
		my $wordmonth=monthtonum($month);
	
		my $thiskey="$curyear"."$wordmonth"."$day";
		#print "thiskey is $thiskey\n";
		
		
	
		print OUT "\<tr\>\<td\>";
		if ($longass =~ /$thiskey/)
		{
			print OUT "GETTO!";
		}
		else {$remaining++; $missedthisyear{$curyear}++;}
		print OUT "\<td\>$thiskey\<td\>$song\<td\>$artist\<td\>$stars";
		print OUT "\n";
	}
	else
	{
		#print "line $line had no numbers; \n";
		#print OUT "$origline";
	}
}
print OUT "\<\/table\>";
print OUT "\n\<br>$remaining remaining of $totalsongcount\n\<br\>";
foreach my $year (sort keys %missedthisyear)
{
	print OUT "MISSING in $year:";
	for (my $i=0;$i<"$missedthisyear{$year}";$i++)
	{
		print OUT "\*";
	}
	print OUT "\n\<br\>";
}

close OUT;
print "$remaining remaining of $totalsongcount\n";

