#!/usr/bin/perl -wa use strict; require "html_escape.perl"; ########################################################### sub by_title_occurance { return 0 if ( !exists ($a->{"Band"}) ); return 0 if ( !exists ($b->{"Band"}) ); return 0 if ( !exists ($a->{"Title"}) ); return 0 if ( !exists ($b->{"Title"}) ); return 0 if ( !exists ($a->{"BandOccurance"}) ); return 0 if ( !exists ($b->{"BandOccurance"}) ); return 0 if ( !exists ($a->{"TitleOccurance"}) ); return 0 if ( !exists ($b->{"TitleOccurance"}) ); return ($b->{"TitleOccurance"} - $a->{"TitleOccurance"}) || ($b->{"BandOccurance"} - $a->{"BandOccurance"}) || ($a->{"Band"} cmp $b->{"Band"}) || ($a->{"Title"} cmp $b->{"Title"}); } ########################################################### sub by_band_occurance { return 0 if ( !exists ($a->{"Band"}) ); return 0 if ( !exists ($b->{"Band"}) ); return 0 if ( !exists ($a->{"Title"}) ); return 0 if ( !exists ($b->{"Title"}) ); return 0 if ( !exists ($a->{"BandOccurance"}) ); return 0 if ( !exists ($b->{"BandOccurance"}) ); return 0 if ( !exists ($a->{"TitleOccurance"}) ); return 0 if ( !exists ($b->{"TitleOccurance"}) ); return ($b->{"BandOccurance"} - $a->{"BandOccurance"}) || ($a->{"Band"} cmp $b->{"Band"}) || ($a->{"Title"} cmp $b->{"Title"}); } ########################################################### if (1) { ########################################################### foreach my $cmd (@ARGV) { if ($cmd eq "--help") { print "mh: Creates mh.html - a webpage showing what music I listen to...\n"; print "\n"; print "Usage: mh\n"; print "\n"; print "mh --help\n"; print "mh --version\n"; exit(0); } if ($cmd eq "--version") { print "1.0\n"; exit(0); } } ########################################################### my @music_list = (); my %band_count = (); my @filelist = ("index.html", "20040622.html", "20020727.html", "20011230.html", "20010810.html", "20010515.html", "20010221.html", "20001015.html", "20000515.html"); foreach my $in_filename (@filelist) { open (IN, "../$in_filename") || die("Cannot open $in_filename for reading: $!...\n"); while (my $line = ) { my $band = ""; my $title = ""; if ($line =~ m@Current Mood / Music : (?:[^\\/]+) / ([^\\-]+) - "([^\\"]+)"@) { $band = $1; $title = $2; } else { if ($line =~ m/Music : ([^\\-]+) - "([^\\"]+)"/) { if ($1 ne "\$band_name" && $2 ne "\$song_name") { $band = $1; $title = $2; } } } if ($band ne "" && $title ne "") { $band = "Bad Religion" if ($band eq "BR"); $band = "Less Than Jake" if ($band eq "LTJ"); $band = "No Use For A Name" if ($band eq "NUFAN"); $band = "Reel Big Fish" if ($band eq "RBF"); $band = "Red Hot Chilli Peppers" if ($band eq "RHCP"); push(@music_list, {"Band"=>"$band", "Title"=>"$title", "TitleOccurance"=>0, "BandOccurance"=>0}); if ( !exists($band_count{"$band"}) ) { $band_count{"$band"} = 1; } else { $band_count{"$band"} += 1; } if ( !exists($band_count{"$band" ."_" . "$title"}) ) { $band_count{"$band" ."_" . "$title"} = 1; } else { $band_count{"$band" ."_" . "$title"} += 1; } } } close (IN) || die("Cannot close $in_filename: $!\n"); } for (my $j = 0; $j <= $#music_list; $j++) { $music_list[$j]{"BandOccurance"} = $band_count{$music_list[$j]{"Band"}}; $music_list[$j]{"TitleOccurance"} = $band_count{$music_list[$j]{"Band"} . "_" . $music_list[$j]{"Title"}}; } foreach my $out_filename ( ("mh.html", "mh.xml") ) { open (OUT, ">$out_filename") || die("Cannot open $out_filename for writing: $!...\n"); @music_list = sort by_title_occurance (@music_list); if ($out_filename eq "mh.html") { print OUT "\n"; print OUT "\n"; print OUT "\n\n\tMusic habits\n\n"; print OUT "\n\n"; print OUT "

My music habits...

\n"; print OUT "
This file is generated by reading my news pages and gathering what songs I've been listening to...
\n"; print OUT "
It then takes that information and sorts it and based on how much I've told people I'm listening to something,
\n"; print OUT "
that's how much I must like it...
\n"; print OUT "



\n\n"; print OUT "

My favorite song(s) must be:

\n"; } else { print OUT "\n"; print OUT "\n"; print OUT "\n"; } if ($out_filename eq "mh.html") { } else { print OUT "\n"; } for (my $j = 0; $j <= $#music_list; $j++) { if (($music_list[$j]{"TitleOccurance"} == $music_list[0]{"TitleOccurance"}) && ($j == 0 || $music_list[$j]{"Title"}) ne $music_list[$j - 1]{"Title"}) { my $band = html_escape($music_list[$j]{"Band"}); my $title = html_escape($music_list[$j]{"Title"}); if ($out_filename eq "mh.html") { print OUT "
'$band' - '$title'
\n"; } else { print OUT "\n"; } } } if ($out_filename eq "mh.html") { } else { print OUT "
\n"; } @music_list = sort by_band_occurance (@music_list); if ($out_filename eq "mh.html") { print OUT "



\n\n"; print OUT "

My favorite band(s) must be:


\n"; } if ($out_filename eq "mh.html") { } else { print OUT "\n"; } for (my $j = 0; $j <= $#music_list; $j++) { if (($music_list[$j]{"BandOccurance"} == $music_list[0]{"BandOccurance"}) && ($j == 0 || $music_list[$j]{"Band"}) ne $music_list[$j - 1]{"Band"}) { my $band = html_escape($music_list[$j]{"Band"}); if ($out_filename eq "mh.html") { print OUT "
$band
\n"; } else { print OUT "\n"; } } } if ($out_filename eq "mh.html") { } else { print OUT "
\n"; } if ($out_filename eq "mh.html") { print OUT "



\n\n"; print OUT "

Song listing alphabetically by favourite bands:

\n"; } for (my $j = 0; $j <= $#music_list; $j++) { my $band = html_escape($music_list[$j]{"Band"}); my $title = html_escape($music_list[$j]{"Title"}); if ($out_filename eq "mh.html") { print OUT "
$band - $title
\n"; } else { print OUT "\n"; } } if ($out_filename eq "mh.html") { print OUT "\n


By Flikky!
\n\n"; print OUT "\n"; print OUT "\n"; } else { print OUT "
\n"; } close (OUT) || die("Cannot close $out_filename: $!\n"); } }