Subversion Repositories HomeAutomation

Rev

Rev 510 | Rev 590 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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