Subversion Repositories HomeAutomation

Rev

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

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