Subversion Repositories HomeAutomation

Rev

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

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