Rev 892 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 505 | arune | 1 | #!/usr/bin/perl -w |
| 2 | |||
| 3 | $debugmode = 0; |
||
| 4 | |||
| 892 | arune | 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"; |
||
| 506 | arune | 12 | $contentsheader = "====== Log of #hobby-channel ======\n"; |
| 892 | arune | 13 | #$namespace = "common:irc:hobby:"; |
| 505 | arune | 14 | |
| 892 | arune | 15 | #require "settings.pl"; |
| 16 | use File::Copy; |
||
| 596 | arune | 17 | |
| 505 | arune | 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 | |||
| 892 | arune | 49 | if ($numArgs == 2) { |
| 50 | if ($ARGV[0] eq "-s") { |
||
| 51 | require "$ARGV[1]"; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 505 | arune | 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/) { |
||
| 892 | arune | 63 | print "Not a number: $startAtLine\n"; |
| 505 | arune | 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 | |||
| 596 | arune | 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"); |
| 511 | arune | 107 | $nrofcolors = @colors; |
| 108 | |||
| 505 | arune | 109 | $linecnt = 0; |
| 110 | while (<LOGFILE>) { |
||
| 111 | #print $linecnt ." "; |
||
| 112 | $line = $_; |
||
| 113 | #$store = ""; |
||
| 114 | if ($linecnt >= $startAtLine) { |
||
| 892 | arune | 115 | if ($line =~ m/^Session Time:/ || $line =~ m/^Session Start:/) { |
| 505 | arune | 116 | #print $line; |
| 117 | $datetimenice = $line; |
||
| 118 | $datetimenice =~ s/Session Time: //g; |
||
| 892 | arune | 119 | $datetimenice =~ s/Session Start: //g; |
| 505 | arune | 120 | $datetimenice =~ s/\n//g; |
| 121 | $datetimenice =~ s/\r//g; |
||
| 122 | |||
| 123 | $datetime = $line; |
||
| 124 | $datetime =~ s/Session Time: //g; |
||
| 892 | arune | 125 | $datetime =~ s/Session Start: //g; |
| 505 | arune | 126 | $datetime =~ s/://g; |
| 127 | $datetime =~ s/\n//g; |
||
| 128 | $datetime =~ s/\r//g; |
||
| 129 | $datetime =~ s/ /_/g; |
||
| 507 | arune | 130 | $datetime = lc($datetime); |
| 505 | arune | 131 | |
| 728 | arune | 132 | if ($currentfile) { |
| 133 | if ($debugmode == 0) { |
||
| 134 | print OUTFILE "\n\\\\\nNext page: [[".$datetime."]] \\\\ \n"; |
||
| 135 | print OUTFILE "Back to index: [[".$namespace."]] \\\\ \n"; |
||
| 892 | arune | 136 | close(OUTFILE); |
| 728 | arune | 137 | |
| 892 | arune | 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 | } |
||
| 728 | arune | 143 | } |
| 144 | } |
||
| 145 | |||
| 505 | arune | 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) { |
||
| 507 | arune | 156 | print CONTENTSFILE "[[$namespace$datetime|$datetimenice]] \\\\ \n"; |
| 505 | arune | 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 | } |
||
| 728 | arune | 175 | if ($currentfile) { |
| 176 | if ($debugmode == 0) { |
||
| 177 | print OUTFILE "====== ".$datetimenice." ======\n"; |
||
| 178 | } |
||
| 179 | } |
||
| 505 | arune | 180 | #print $datetime; |
| 181 | } |
||
| 182 | |||
| 728 | arune | 183 | elsif ($currentfile) { |
| 505 | arune | 184 | $parsedLine = $line; |
| 185 | $parsedLine =~ s/\n//g; |
||
| 186 | $parsedLine =~ s/\r//g; |
||
| 507 | arune | 187 | #$parsedLine = $parsedLine; |
| 510 | arune | 188 | |
| 511 | arune | 189 | #<color #aaaaaa> |
| 190 | #</color> |
||
| 191 | |||
| 510 | arune | 192 | $nickLine = $parsedLine; |
| 193 | if ($nickLine =~ m/.*<(\w{1,9})>.*/) { |
||
| 194 | $nick = $1; |
||
| 195 | $nickVal = 0; |
||
| 511 | arune | 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 | |||
| 510 | arune | 203 | } |
| 596 | arune | 204 | #$temp = $nickVal; |
| 511 | arune | 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 | #} |
||
| 510 | arune | 218 | |
| 596 | arune | 219 | #print "$nick $temp $nickVal $colors[$nickVal] \n"; |
| 511 | arune | 220 | #$color = "#$nickR$nickG$nickB"; |
| 221 | $parsedLine =~ s/<$nick>/<color $colors[$nickVal]><$nick><\/color>/; |
||
| 510 | arune | 222 | #print $nick." ".$nickVal."\n"; |
| 223 | #print $parsedLine ."\n"; |
||
| 224 | } |
||
| 505 | arune | 225 | |
| 892 | arune | 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 | |||
| 507 | arune | 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; |
||
| 590 | arune | 246 | |
| 594 | arune | 247 | $parsedLine .= " "; |
| 892 | arune | 248 | $parsedLine =~ s/http:\/\/projekt\.auml\.se\/(\S+)/[[:$1]] /g; |
| 507 | arune | 249 | |
| 505 | arune | 250 | $parsedLine .= "\\\\"."\n"; |
| 251 | if ($debugmode == 0) { |
||
| 252 | print OUTFILE $parsedLine; |
||
| 253 | } |
||
| 254 | } |
||
| 255 | #print $store; |
||
| 256 | |||
| 257 | } |
||
| 258 | $linecnt++; |
||
| 259 | } |
||
| 892 | arune | 260 | close(OUTFILE); |
| 505 | arune | 261 | |
| 892 | arune | 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 | |||
| 505 | arune | 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 | |||
| 506 | arune | 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) { |
||
| 892 | arune | 298 | print NICECONTENTSFILE $_; |
| 506 | arune | 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 | |||
| 505 | arune | 312 | #print $linecnt-1 ." - ". $line; |