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