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