#!/usr/bin/perl
#------------------------------------------------#

# PROGRAM: Raport dotyczący fraz wyszukiwania #
#------------------------------------------------#
$numArgs = $#ARGV + 1;
%googleDirCnt = ();
foreach $argnum (0 .. $#ARGV) {
print "Analizowanie pliku $ARGV[$argnum] \n\n";
$LOGFILE = "$ARGV[$argnum]";
open(LOGFILE) or die("Nie można otworzyć pliku: $ARGV[$argnum].");
foreach $line (<LOGFILE>) {
#Analiza Google
if(($line =~ /q=/) && ($line =~ /google/)) {
@tmp1 = split ('GET ',$line);
@tmp2 = split (' ', $tmp1[1]);
@tmp3 = split ('q=', $tmp1[1]);
@tmp4 = split ('\&', $tmp3[1]);
#Czyszczenie
$tmp4[0] =~ s/\+/ /;
$tmp4[0] =~ s/\%20/ /g;
$tmp4[0] =~ s/\%3C/\</gi;
$tmp4[0] =~ s/\%3E/\>/gi;
$tmp4[0] =~ s/\%23/\#/g;
$tmp4[0] =~ s/\%22/\"/g;
$tmp4[0] =~ s/\%25/\%/g;
$tmp4[0] =~ s/\%3A/\:/gi;
$tmp4[0] =~ s/\%2F/\//gi;
$tmp4[0] =~ s/\%2B/\+/gi;
@tmp5 = split ('\"', $tmp4[0]);
$tmpKey = "<tr><td>".$tmp2[0]." </td><td>".$tmp5[0]."</td>";
$googleDirCnt{$tmpKey} = $googleDirCnt{$tmpKey} +1;
}
}
close(LOGFILE);
}
open (FP, '>keywordsummary.html');
print FP "<html><head><title>Podsumowanie słów kluczowych</title><head>";
print FP "<body><strong>Podsumowanie dla wyszukiwarki Google</strong>";
print FP "<table width=400><tr><td><b>Adres URL/Źródło</b></td><td><b>Słowa kluczowe</b></td>";
print FP "<td><b>Suma</b></td><tr>";
foreach $key (sort hashValueDescendingNum (keys(%googleDirCnt))) {
print FP $key."<td>".$googleDirCnt{$key}."</td></tr>";
}
print FP "</table></body></html>";
close (FP);
sub hashValueDescendingNum {
$googleDirCnt{$b} <=> $googleDirCnt{$a};
}