Subversion Repositories HomeAutomation

Rev

Rev 510 | Rev 590 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 510 Rev 511
Line 1... Line 1...
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 = $_;
Line 154... Line 154...
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;