Subversion Repositories HomeAutomation

Rev

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

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