Subversion Repositories HomeAutomation

Rev

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