Subversion Repositories HomeAutomation

Rev

Rev 507 | Rev 511 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. #!/usr/bin/perl -w
  2.  
  3. use Encode;
  4.    
  5. $debugmode = 0;
  6.  
  7. $outputpath = "H:/shared/www/projekt/data/pages/common/irc/hobby/";
  8. $linenrpath = "linenr.txt";
  9. $contentspath = "contents.txt";
  10. $currentfilepath = "currentfile.txt";
  11. $logfilepath = "C:/Prgm/mIRC/logs/EFnet/#hobby.log";
  12. $contentsfileoutput = "H:/shared/www/projekt/data/pages/common/irc/";
  13. $contentsfilename = "hobby.txt";
  14. $contentsheader = "====== Log of #hobby-channel ======\n";
  15. $namespace = "common:irc:hobby:";
  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.  
  49. $startAtLine = 0;
  50. $currentfile = "";
  51.  
  52. $fileopenerr = 0;
  53. open (LINENR, "<".$linenrpath) or $fileopenerr = 1;
  54. if ($fileopenerr == 0) {
  55.     $startAtLine = <LINENR>;
  56.     if ($startAtLine =~ /\D/) {
  57.         print "Not a number\n";
  58.         exit;
  59.     }
  60.     close(LINENR);
  61. } else {
  62.     print "Could not open ".$linenrpath;
  63.     exit;
  64. }
  65.  
  66. $fileopenerr = 0;
  67. open (CURRFILE, "<".$currentfilepath) or $fileopenerr = 1;
  68. if ($fileopenerr == 0) {
  69.     $currentfile = <CURRFILE>;
  70.     if (!$currentfile && $startAtLine != 0) {
  71.         print "Current file not ok\n";
  72.         exit;
  73.     }
  74.     close(CURRFILE);
  75. } else {
  76.     print "Could not opeen ".$currentfilepath;
  77.     if ($startAtLine != 0) {
  78.         exit;
  79.     }
  80. }
  81.  
  82. $fileopenerr = 0;
  83. open (LOGFILE, "<".$logfilepath) or $fileopenerr = 1;
  84. if ($fileopenerr == 1) {
  85.     print "Could not open ".$logfilepath;
  86.     exit;
  87. }
  88.  
  89. if ($currentfile) {
  90.     if ($debugmode == 0) {
  91.         $fileopenerr = 0;
  92.         open (OUTFILE, ">>".$outputpath.$currentfile) or $fileopenerr = 1;
  93.         if ($fileopenerr == 1) {
  94.             print "Could not open ".$outputpath."/".$currentfile;
  95.             exit;
  96.         }
  97.     }
  98. }
  99.  
  100. $linecnt = 0;
  101. while (<LOGFILE>) {
  102.     #print $linecnt ." ";
  103.     $line = $_;
  104.     #$store = "";
  105.     if ($linecnt >= $startAtLine) {
  106.         if ($line =~ m/^Session Time:/) {
  107.             #print $line;
  108.             $datetimenice = $line;
  109.             $datetimenice =~ s/Session Time: //g;
  110.             $datetimenice =~ s/\n//g;
  111.             $datetimenice =~ s/\r//g;
  112.            
  113.             $datetime = $line;
  114.             $datetime =~ s/Session Time: //g;
  115.             $datetime =~ s/://g;
  116.             $datetime =~ s/\n//g;
  117.             $datetime =~ s/\r//g;
  118.             $datetime =~ s/ /_/g;
  119.             $datetime = lc($datetime);
  120.  
  121.             $currentfile = $datetime .".txt";
  122.             # skriv $datetimenice och $datetime till $contentspath
  123.             $fileopenerr = 0;
  124.             open (CONTENTSFILE, "<".$contentspath) or $fileopenerr = 1;
  125.             if ($fileopenerr == 0) {
  126.                 @contentsfilecontents = <CONTENTSFILE>;
  127.                 close(CONTENTSFILE);
  128.                 if ($debugmode == 0) {
  129.                     open (CONTENTSFILE, ">".$contentspath) or $fileopenerr = 1;
  130.                     if ($fileopenerr == 0) {
  131.                         print CONTENTSFILE "[[$namespace$datetime|$datetimenice]] \\\\ \n";
  132.                         foreach (@contentsfilecontents) {
  133.                             print CONTENTSFILE $_;
  134.                         }
  135.                         close(CONTENTSFILE);
  136.                     }
  137.                 }
  138.             } else {
  139.                 exit;
  140.             }
  141.  
  142.             if ($debugmode == 0) {
  143.                 $fileopenerr = 0;
  144.                 open (OUTFILE, ">>".$outputpath.$currentfile) or $fileopenerr = 1;
  145.                 if ($fileopenerr == 1) {
  146.                     print "Could not open ".$outputpath."/".$currentfile;
  147.                     exit;
  148.                 }
  149.             }
  150.  
  151.             #print $datetime;
  152.         }
  153.        
  154.         if ($currentfile) {
  155.             $parsedLine = $line;
  156.             $parsedLine =~ s/\n//g;
  157.             $parsedLine =~ s/\r//g;
  158.             #$parsedLine = $parsedLine;
  159.  
  160.             $nickLine = $parsedLine;
  161.             if ($nickLine =~ m/.*<(\w{1,9})>.*/) {
  162.                 $nick = $1;
  163.                 $nickVal = 0;
  164.                 for ($i = 0; $i < length($nick); $i++) {
  165.                     $nickVal += ord(substr($nick, $i, 1));
  166.                 }
  167.                 $nickVal = ($nickVal) % 512;
  168.                 $nickB = sprintf("%x", ((($nickVal & 7)**2)*2.3+5));
  169.                 $nickG = sprintf("%x", (((($nickVal >> 3) & 7)**2.3)*2+5));
  170.                 $nickR = sprintf("%x", (((($nickVal >> 6) & 7)**2.3)*2+5));
  171.                 if (length($nickB) == 1) {
  172.                     $nickB = "0".$nickB;
  173.                 }
  174.                 if (length($nickG) == 1) {
  175.                     $nickG = "0".$nickG;
  176.                 }
  177.                 if (length($nickR) == 1) {
  178.                     $nickR = "0".$nickR;
  179.                 }
  180.                
  181.                 #print "$nick $nickR$nickG$nickB\n";
  182.                 $color = "#$nickR$nickG$nickB";
  183.                 $parsedLine =~ s/<$nick>/<color $color><$nick><\/color>/;
  184.                 #print $nick." ".$nickVal."\n";
  185.                 #print $parsedLine ."\n";
  186.             }
  187.            
  188.             $parsedLine =~ s/\x{e5}/å/g;
  189.             $parsedLine =~ s/\x{e4}/ä/g;
  190.             $parsedLine =~ s/\x{f6}/ö/g;
  191.             $parsedLine =~ s/\x{c5}/Å/g;
  192.             $parsedLine =~ s/\x{c4}/Ä/g;
  193.             $parsedLine =~ s/\x{d6}/Ö/g;
  194.  
  195.             $parsedLine =~ s/\[wiki\]/**[wiki]**/g;
  196.             $parsedLine =~ s/\[svn\]/**[svn]**/g;
  197.            
  198.             $parsedLine .= "\\\\"."\n";
  199.             if ($debugmode == 0) {
  200.                 print OUTFILE $parsedLine;
  201.             }
  202.         }
  203.         #print $store;
  204.        
  205.     }
  206.     $linecnt++;
  207. }
  208.  
  209. if ($debugmode == 0) {
  210.     $fileopenerr = 0;
  211.     open (LINENR, ">".$linenrpath) or $fileopenerr = 1;
  212.     if ($fileopenerr == 0) {
  213.         print LINENR $linecnt;
  214.         close(LINENR);
  215.     }
  216. }
  217.  
  218. if ($debugmode == 0) {
  219.     $fileopenerr = 0;
  220.     open (CURRFILE, ">".$currentfilepath) or $fileopenerr = 1;
  221.     if ($fileopenerr == 0) {
  222.         print CURRFILE $currentfile;
  223.         close(CURRFILE);
  224.     } else {
  225.         print "Could not open ".$currentfilepath;
  226.         exit;
  227.     }
  228. }
  229.  
  230. if ($debugmode == 0) {
  231.     $fileopenerr = 0;
  232.     open (CONTENTSFILE, "<".$contentspath) or $fileopenerr = 1;
  233.     if ($fileopenerr == 0) {
  234.         open (NICECONTENTSFILE, ">".$contentsfileoutput.$contentsfilename) or $fileopenerr = 1;
  235.         if ($fileopenerr == 0) {
  236.             @contentsfilecontents = <CONTENTSFILE>;
  237.             print NICECONTENTSFILE $contentsheader;
  238.             foreach (@contentsfilecontents) {
  239.                             print NICECONTENTSFILE $_;
  240.             }
  241.             close(NICECONTENTSFILE);
  242.         } else {
  243.             print "Could not open ".$contentsfileoutput.$contentsfilename;
  244.             exit;
  245.         }
  246.         close(CONTENTSFILE);
  247.     } else {
  248.         print "Could not open ".$contentspath;
  249.         exit;
  250.     }
  251. }
  252.  
  253. #print $linecnt-1 ." - ". $line;
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.