Subversion Repositories HomeAutomation

Rev

Rev 728 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. #!/usr/bin/perl -w
  2.  
  3. $debugmode = 0;
  4.  
  5. $outputpath = "outp/";
  6. $linenrpath = "linenr.txt";
  7. $contentspath = "contents.txt";
  8. $currentfilepath = "currentfile.txt";
  9. $logfilepath = "#hobby_small.log";
  10. $contentsfileoutput = "outp/";
  11. $contentsfilename = "hobby.txt";
  12. $contentsheader = "====== Log of #hobby-channel ======\n";
  13. $namespace = "common:irc:hobby:";
  14.  
  15. require "settings.pl";
  16.  
  17. $numArgs = $#ARGV + 1;
  18. if ($numArgs == 1) {
  19.     if ($ARGV[0] eq "-r") {
  20.         #reset log system
  21.        
  22.         $fileopenerr = 0;
  23.         open (LINENR, ">".$linenrpath) or $fileopenerr = 1;
  24.         if ($fileopenerr == 0) {
  25.             print LINENR "0";
  26.             close(LINENR);
  27.         }
  28.        
  29.         $fileopenerr = 0;
  30.         open (CONTENTSFILE, ">".$contentspath) or $fileopenerr = 1;
  31.         if ($fileopenerr == 0) {
  32.             print CONTENTSFILE "";
  33.             close(CONTENTSFILE);
  34.         }
  35.         close(CONTENTSFILE);
  36.  
  37.         $fileopenerr = 0;
  38.         open (CURRFILE, ">".$currentfilepath) or $fileopenerr = 1;
  39.         if ($fileopenerr == 0) {
  40.             print CURRFILE "";
  41.             close(CURRFILE);
  42.         }      
  43.         #print "exit\n";
  44.         exit;
  45.     }
  46. }
  47.  
  48. $startAtLine = 0;
  49. $currentfile = "";
  50.  
  51. $fileopenerr = 0;
  52. open (LINENR, "<".$linenrpath) or $fileopenerr = 1;
  53. if ($fileopenerr == 0) {
  54.     $startAtLine = <LINENR>;
  55.     if ($startAtLine =~ /\D/) {
  56.         print "Not a number\n";
  57.         exit;
  58.     }
  59.     close(LINENR);
  60. } else {
  61.     print "Could not open ".$linenrpath;
  62.     exit;
  63. }
  64.  
  65. $fileopenerr = 0;
  66. open (CURRFILE, "<".$currentfilepath) or $fileopenerr = 1;
  67. if ($fileopenerr == 0) {
  68.     $currentfile = <CURRFILE>;
  69.     if (!$currentfile && $startAtLine != 0) {
  70.         print "Current file not ok\n";
  71.         exit;
  72.     }
  73.     close(CURRFILE);
  74. } else {
  75.     print "Could not opeen ".$currentfilepath;
  76.     if ($startAtLine != 0) {
  77.         exit;
  78.     }
  79. }
  80.  
  81. $fileopenerr = 0;
  82. open (LOGFILE, "<".$logfilepath) or $fileopenerr = 1;
  83. if ($fileopenerr == 1) {
  84.     print "Could not open ".$logfilepath;
  85.     exit;
  86. }
  87.  
  88. if ($currentfile) {
  89.     if ($debugmode == 0) {
  90.         $fileopenerr = 0;
  91.         open (OUTFILE, ">>".$outputpath.$currentfile) or $fileopenerr = 1;
  92.         if ($fileopenerr == 1) {
  93.             print "Could not open ".$outputpath."/".$currentfile;
  94.             exit;
  95.         }
  96.     }
  97. }
  98.  
  99. @colors = ("#2F4F4F","#696969","#A0522D","#D2691E","#DAA520","#191970","#0000CD","#4682B4","#7FEFD4","#556B2F","#008B8B","#808000","#2E8B57","#32CD32","#483D8B","#6A5ACD","#8A2BE2","#BDB76B","#EF4500","#C71585","#8B0000","#DC143C","#E9967A","#CD5C5C","#B0E0E6","#E0E0C0");
  100. $nrofcolors = @colors;
  101.  
  102. $linecnt = 0;
  103. while (<LOGFILE>) {
  104.     #print $linecnt ." ";
  105.     $line = $_;
  106.     #$store = "";
  107.     if ($linecnt >= $startAtLine) {
  108.         if ($line =~ m/^Session Time:/) {
  109.             #print $line;
  110.             $datetimenice = $line;
  111.             $datetimenice =~ s/Session Time: //g;
  112.             $datetimenice =~ s/\n//g;
  113.             $datetimenice =~ s/\r//g;
  114.            
  115.             $datetime = $line;
  116.             $datetime =~ s/Session Time: //g;
  117.             $datetime =~ s/://g;
  118.             $datetime =~ s/\n//g;
  119.             $datetime =~ s/\r//g;
  120.             $datetime =~ s/ /_/g;
  121.             $datetime = lc($datetime);
  122.  
  123.             if ($currentfile) {
  124.                 if ($debugmode == 0) {
  125.                     print OUTFILE "\n\\\\\nNext page: [[".$datetime."]] \\\\ \n";
  126.                     print OUTFILE "Back to index: [[".$namespace."]] \\\\ \n";
  127.                    
  128.                 }              
  129.             }
  130.  
  131.             $currentfile = $datetime .".txt";
  132.             # skriv $datetimenice och $datetime till $contentspath
  133.             $fileopenerr = 0;
  134.             open (CONTENTSFILE, "<".$contentspath) or $fileopenerr = 1;
  135.             if ($fileopenerr == 0) {
  136.                 @contentsfilecontents = <CONTENTSFILE>;
  137.                 close(CONTENTSFILE);
  138.                 if ($debugmode == 0) {
  139.                     open (CONTENTSFILE, ">".$contentspath) or $fileopenerr = 1;
  140.                     if ($fileopenerr == 0) {
  141.                         print CONTENTSFILE "[[$namespace$datetime|$datetimenice]] \\\\ \n";
  142.                         foreach (@contentsfilecontents) {
  143.                             print CONTENTSFILE $_;
  144.                         }
  145.                         close(CONTENTSFILE);
  146.                     }
  147.                 }
  148.             } else {
  149.                 exit;
  150.             }
  151.  
  152.             if ($debugmode == 0) {
  153.                 $fileopenerr = 0;
  154.                 open (OUTFILE, ">>".$outputpath.$currentfile) or $fileopenerr = 1;
  155.                 if ($fileopenerr == 1) {
  156.                     print "Could not open ".$outputpath."/".$currentfile;
  157.                     exit;
  158.                 }
  159.             }
  160.             if ($currentfile) {
  161.                 if ($debugmode == 0) {
  162.                     print OUTFILE "====== ".$datetimenice." ======\n";
  163.                 }              
  164.             }
  165.             #print $datetime;
  166.         }
  167.        
  168.         elsif ($currentfile) {
  169.             $parsedLine = $line;
  170.             $parsedLine =~ s/\n//g;
  171.             $parsedLine =~ s/\r//g;
  172.             #$parsedLine = $parsedLine;
  173.  
  174.             #<color #aaaaaa>
  175.             #</color>  
  176.            
  177.             $nickLine = $parsedLine;
  178.             if ($nickLine =~ m/.*<(\w{1,9})>.*/) {
  179.                 $nick = $1;
  180.                 $nickVal = 0;
  181.                 my @chars = split //, $nick;
  182.                 foreach my $char (@chars) {
  183.                 #for ($i = 0; $i < length($nick); $i++) {
  184.                     #$charval = ord(substr($nick, $i, 1));
  185.                     $nickVal += ord($char);
  186.                     #$nickVal += $charval;
  187.                    
  188.                 }
  189.                 #$temp = $nickVal;
  190.                 $nickVal = ($nickVal) % $nrofcolors;
  191.                 #$nickB = sprintf("%x", ((($nickVal & 7)**2)*2.3+5));
  192.                 #$nickG = sprintf("%x", (((($nickVal >> 3) & 7)**2.3)*2+5));
  193.                 #$nickR = sprintf("%x", (((($nickVal >> 6) & 7)**2.3)*2+5));
  194.                 #if (length($nickB) == 1) {
  195.                 #   $nickB = "0".$nickB;
  196.                 #}
  197.                 #if (length($nickG) == 1) {
  198.                 #   $nickG = "0".$nickG;
  199.                 #}
  200.                 #if (length($nickR) == 1) {
  201.                 #   $nickR = "0".$nickR;
  202.                 #}
  203.                
  204.                 #print "$nick $temp $nickVal $colors[$nickVal] \n";
  205.                 #$color = "#$nickR$nickG$nickB";
  206.                 $parsedLine =~ s/<$nick>/<color $colors[$nickVal]><$nick><\/color>/;
  207.                 #print $nick." ".$nickVal."\n";
  208.                 #print $parsedLine ."\n";
  209.             }
  210.            
  211.             $parsedLine =~ s/\x{e5}/å/g;
  212.             $parsedLine =~ s/\x{e4}/ä/g;
  213.             $parsedLine =~ s/\x{f6}/ö/g;
  214.             $parsedLine =~ s/\x{c5}/Å/g;
  215.             $parsedLine =~ s/\x{c4}/Ä/g;
  216.             $parsedLine =~ s/\x{d6}/Ö/g;
  217.  
  218.             $parsedLine =~ s/\[wiki\]/**[wiki]**/g;
  219.             $parsedLine =~ s/\[svn\]/**[svn]**/g;
  220.  
  221.             $parsedLine .= " ";
  222.             $parsedLine =~ s/http:\/\/projekt\.auml\.se\/(.+) /[[:$1]] /g;
  223.            
  224.             $parsedLine .= "\\\\"."\n";
  225.             if ($debugmode == 0) {
  226.                 print OUTFILE $parsedLine;
  227.             }
  228.         }
  229.         #print $store;
  230.        
  231.     }
  232.     $linecnt++;
  233. }
  234.  
  235. if ($debugmode == 0) {
  236.     $fileopenerr = 0;
  237.     open (LINENR, ">".$linenrpath) or $fileopenerr = 1;
  238.     if ($fileopenerr == 0) {
  239.         print LINENR $linecnt;
  240.         close(LINENR);
  241.     }
  242. }
  243.  
  244. if ($debugmode == 0) {
  245.     $fileopenerr = 0;
  246.     open (CURRFILE, ">".$currentfilepath) or $fileopenerr = 1;
  247.     if ($fileopenerr == 0) {
  248.         print CURRFILE $currentfile;
  249.         close(CURRFILE);
  250.     } else {
  251.         print "Could not open ".$currentfilepath;
  252.         exit;
  253.     }
  254. }
  255.  
  256. if ($debugmode == 0) {
  257.     $fileopenerr = 0;
  258.     open (CONTENTSFILE, "<".$contentspath) or $fileopenerr = 1;
  259.     if ($fileopenerr == 0) {
  260.         open (NICECONTENTSFILE, ">".$contentsfileoutput.$contentsfilename) or $fileopenerr = 1;
  261.         if ($fileopenerr == 0) {
  262.             @contentsfilecontents = <CONTENTSFILE>;
  263.             print NICECONTENTSFILE $contentsheader;
  264.             foreach (@contentsfilecontents) {
  265.                             print NICECONTENTSFILE $_;
  266.             }
  267.             close(NICECONTENTSFILE);
  268.         } else {
  269.             print "Could not open ".$contentsfileoutput.$contentsfilename;
  270.             exit;
  271.         }
  272.         close(CONTENTSFILE);
  273.     } else {
  274.         print "Could not open ".$contentspath;
  275.         exit;
  276.     }
  277. }
  278.  
  279. #print $linecnt-1 ." - ". $line;
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.