Rev 510 | Rev 590 | Go to most recent revision | 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 | |||
| 511 | arune | 5 | $outputpath = "outp/"; |
| 505 | arune | 6 | $linenrpath = "linenr.txt"; |
| 7 | $contentspath = "contents.txt"; |
||
| 8 | $currentfilepath = "currentfile.txt"; |
||
| 511 | arune | 9 | $logfilepath = "#hobby_small.log"; |
| 10 | $contentsfileoutput = "outp/"; |
||
| 506 | arune | 11 | $contentsfilename = "hobby.txt"; |
| 12 | $contentsheader = "====== Log of #hobby-channel ======\n"; |
||
| 507 | arune | 13 | $namespace = "common:irc:hobby:"; |
| 505 | arune | 14 | |
| 15 | $numArgs = $#ARGV + 1; |
||
| 16 | if ($numArgs == 1) { |
||
| 17 | if ($ARGV[0] eq "-r") { |
||
| 18 | #reset log system |
||
| 19 | |||
| 20 | $fileopenerr = 0; |
||
| 21 | open (LINENR, ">".$linenrpath) or $fileopenerr = 1; |
||
| 22 | if ($fileopenerr == 0) { |
||
| 23 | print LINENR "0"; |
||
| 24 | close(LINENR); |
||
| 25 | } |
||
| 26 | |||
| 27 | $fileopenerr = 0; |
||
| 28 | open (CONTENTSFILE, ">".$contentspath) or $fileopenerr = 1; |
||
| 29 | if ($fileopenerr == 0) { |
||
| 30 | print CONTENTSFILE ""; |
||
| 31 | close(CONTENTSFILE); |
||
| 32 | } |
||
| 33 | close(CONTENTSFILE); |
||
| 34 | |||
| 35 | $fileopenerr = 0; |
||
| 36 | open (CURRFILE, ">".$currentfilepath) or $fileopenerr = 1; |
||
| 37 | if ($fileopenerr == 0) { |
||
| 38 | print CURRFILE ""; |
||
| 39 | close(CURRFILE); |
||
| 40 | } |
||
| 41 | #print "exit\n"; |
||
| 42 | exit; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | $startAtLine = 0; |
||
| 47 | $currentfile = ""; |
||
| 48 | |||
| 49 | $fileopenerr = 0; |
||
| 50 | open (LINENR, "<".$linenrpath) or $fileopenerr = 1; |
||
| 51 | if ($fileopenerr == 0) { |
||
| 52 | $startAtLine = <LINENR>; |
||
| 53 | if ($startAtLine =~ /\D/) { |
||
| 54 | print "Not a number\n"; |
||
| 55 | exit; |
||
| 56 | } |
||
| 57 | close(LINENR); |
||
| 58 | } else { |
||
| 59 | print "Could not open ".$linenrpath; |
||
| 60 | exit; |
||
| 61 | } |
||
| 62 | |||
| 63 | $fileopenerr = 0; |
||
| 64 | open (CURRFILE, "<".$currentfilepath) or $fileopenerr = 1; |
||
| 65 | if ($fileopenerr == 0) { |
||
| 66 | $currentfile = <CURRFILE>; |
||
| 67 | if (!$currentfile && $startAtLine != 0) { |
||
| 68 | print "Current file not ok\n"; |
||
| 69 | exit; |
||
| 70 | } |
||
| 71 | close(CURRFILE); |
||
| 72 | } else { |
||
| 73 | print "Could not opeen ".$currentfilepath; |
||
| 74 | if ($startAtLine != 0) { |
||
| 75 | exit; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | $fileopenerr = 0; |
||
| 80 | open (LOGFILE, "<".$logfilepath) or $fileopenerr = 1; |
||
| 81 | if ($fileopenerr == 1) { |
||
| 82 | print "Could not open ".$logfilepath; |
||
| 83 | exit; |
||
| 84 | } |
||
| 85 | |||
| 86 | if ($currentfile) { |
||
| 87 | if ($debugmode == 0) { |
||
| 88 | $fileopenerr = 0; |
||
| 89 | open (OUTFILE, ">>".$outputpath.$currentfile) or $fileopenerr = 1; |
||
| 90 | if ($fileopenerr == 1) { |
||
| 91 | print "Could not open ".$outputpath."/".$currentfile; |
||
| 92 | exit; |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 511 | arune | 97 | @colors = ("#2F4F4F","#696969","#A0522D","#D2691E","#DAA520","#191970","#0000CD","#4682B4","#7FFFD4","#556B2F","#008B8B","#808000","#2E8B57","#32CD32","#483D8B","#6A5ACD","#8A2BE2","#BDB76B","#FF4500","#C71585","#8B0000","#DC143C","#E9967A","#CD5C5C","#B0E0E6","#FFEFD5"); |
| 98 | $nrofcolors = @colors; |
||
| 99 | |||
| 505 | arune | 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; |
||
| 507 | arune | 119 | $datetime = lc($datetime); |
| 505 | arune | 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) { |
||
| 507 | arune | 131 | print CONTENTSFILE "[[$namespace$datetime|$datetimenice]] \\\\ \n"; |
| 505 | arune | 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; |
||
| 507 | arune | 158 | #$parsedLine = $parsedLine; |
| 510 | arune | 159 | |
| 511 | arune | 160 | #<color #aaaaaa> |
| 161 | #</color> |
||
| 162 | |||
| 510 | arune | 163 | $nickLine = $parsedLine; |
| 164 | if ($nickLine =~ m/.*<(\w{1,9})>.*/) { |
||
| 165 | $nick = $1; |
||
| 166 | $nickVal = 0; |
||
| 511 | arune | 167 | my @chars = split //, $nick; |
| 168 | foreach my $char (@chars) { |
||
| 169 | #for ($i = 0; $i < length($nick); $i++) { |
||
| 170 | #$charval = ord(substr($nick, $i, 1)); |
||
| 171 | $nickVal += ord($char); |
||
| 172 | #$nickVal += $charval; |
||
| 173 | |||
| 510 | arune | 174 | } |
| 511 | arune | 175 | $temp = $nickVal; |
| 176 | $nickVal = ($nickVal) % $nrofcolors; |
||
| 177 | #$nickB = sprintf("%x", ((($nickVal & 7)**2)*2.3+5)); |
||
| 178 | #$nickG = sprintf("%x", (((($nickVal >> 3) & 7)**2.3)*2+5)); |
||
| 179 | #$nickR = sprintf("%x", (((($nickVal >> 6) & 7)**2.3)*2+5)); |
||
| 180 | #if (length($nickB) == 1) { |
||
| 181 | # $nickB = "0".$nickB; |
||
| 182 | #} |
||
| 183 | #if (length($nickG) == 1) { |
||
| 184 | # $nickG = "0".$nickG; |
||
| 185 | #} |
||
| 186 | #if (length($nickR) == 1) { |
||
| 187 | # $nickR = "0".$nickR; |
||
| 188 | #} |
||
| 510 | arune | 189 | |
| 511 | arune | 190 | print "$nick $temp $nickVal $colors[$nickVal] \n"; |
| 191 | #$color = "#$nickR$nickG$nickB"; |
||
| 192 | $parsedLine =~ s/<$nick>/<color $colors[$nickVal]><$nick><\/color>/; |
||
| 510 | arune | 193 | #print $nick." ".$nickVal."\n"; |
| 194 | #print $parsedLine ."\n"; |
||
| 195 | } |
||
| 505 | arune | 196 | |
| 507 | arune | 197 | $parsedLine =~ s/\x{e5}/å/g; |
| 198 | $parsedLine =~ s/\x{e4}/ä/g; |
||
| 199 | $parsedLine =~ s/\x{f6}/ö/g; |
||
| 200 | $parsedLine =~ s/\x{c5}/Å/g; |
||
| 201 | $parsedLine =~ s/\x{c4}/Ä/g; |
||
| 202 | $parsedLine =~ s/\x{d6}/Ö/g; |
||
| 203 | |||
| 204 | $parsedLine =~ s/\[wiki\]/**[wiki]**/g; |
||
| 205 | $parsedLine =~ s/\[svn\]/**[svn]**/g; |
||
| 206 | |||
| 505 | arune | 207 | $parsedLine .= "\\\\"."\n"; |
| 208 | if ($debugmode == 0) { |
||
| 209 | print OUTFILE $parsedLine; |
||
| 210 | } |
||
| 211 | } |
||
| 212 | #print $store; |
||
| 213 | |||
| 214 | } |
||
| 215 | $linecnt++; |
||
| 216 | } |
||
| 217 | |||
| 218 | if ($debugmode == 0) { |
||
| 219 | $fileopenerr = 0; |
||
| 220 | open (LINENR, ">".$linenrpath) or $fileopenerr = 1; |
||
| 221 | if ($fileopenerr == 0) { |
||
| 222 | print LINENR $linecnt; |
||
| 223 | close(LINENR); |
||
| 224 | } |
||
| 225 | } |
||
| 226 | |||
| 227 | if ($debugmode == 0) { |
||
| 228 | $fileopenerr = 0; |
||
| 229 | open (CURRFILE, ">".$currentfilepath) or $fileopenerr = 1; |
||
| 230 | if ($fileopenerr == 0) { |
||
| 231 | print CURRFILE $currentfile; |
||
| 232 | close(CURRFILE); |
||
| 233 | } else { |
||
| 234 | print "Could not open ".$currentfilepath; |
||
| 235 | exit; |
||
| 236 | } |
||
| 237 | } |
||
| 238 | |||
| 506 | arune | 239 | if ($debugmode == 0) { |
| 240 | $fileopenerr = 0; |
||
| 241 | open (CONTENTSFILE, "<".$contentspath) or $fileopenerr = 1; |
||
| 242 | if ($fileopenerr == 0) { |
||
| 243 | open (NICECONTENTSFILE, ">".$contentsfileoutput.$contentsfilename) or $fileopenerr = 1; |
||
| 244 | if ($fileopenerr == 0) { |
||
| 245 | @contentsfilecontents = <CONTENTSFILE>; |
||
| 246 | print NICECONTENTSFILE $contentsheader; |
||
| 247 | foreach (@contentsfilecontents) { |
||
| 248 | print NICECONTENTSFILE $_; |
||
| 249 | } |
||
| 250 | close(NICECONTENTSFILE); |
||
| 251 | } else { |
||
| 252 | print "Could not open ".$contentsfileoutput.$contentsfilename; |
||
| 253 | exit; |
||
| 254 | } |
||
| 255 | close(CONTENTSFILE); |
||
| 256 | } else { |
||
| 257 | print "Could not open ".$contentspath; |
||
| 258 | exit; |
||
| 259 | } |
||
| 260 | } |
||
| 261 | |||
| 505 | arune | 262 | #print $linecnt-1 ." - ". $line; |
| 263 | |||
| 264 | |||
| 265 | |||
| 266 | |||
| 267 | |||
| 268 | |||
| 269 |