Subversion Repositories HomeAutomation

Rev

Rev 728 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 728 Rev 892
Line 4... Line 4...
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
require "settings.pl";
15
#require "settings.pl";
-
 
16
use File::Copy;
16
 
17
 
17
$numArgs = $#ARGV + 1;
18
$numArgs = $#ARGV + 1;
18
if ($numArgs == 1) {
19
if ($numArgs == 1) {
19
    if ($ARGV[0] eq "-r") {
20
    if ($ARGV[0] eq "-r") {
20
        #reset log system
21
        #reset log system
Line 40... Line 41...
40
            print CURRFILE "";
41
            print CURRFILE "";
41
            close(CURRFILE);
42
            close(CURRFILE);
42
        }      
43
        }      
43
        #print "exit\n";
44
        #print "exit\n";
44
        exit;
45
        exit;
-
 
46
    }
-
 
47
}
-
 
48
 
-
 
49
if ($numArgs == 2) {
-
 
50
    if ($ARGV[0] eq "-s") {
-
 
51
        require "$ARGV[1]";
45
    }
52
    }
46
}
53
}
47
 
54
 
48
$startAtLine = 0;
55
$startAtLine = 0;
49
$currentfile = "";
56
$currentfile = "";
50
 
57
 
51
$fileopenerr = 0;
58
$fileopenerr = 0;
52
open (LINENR, "<".$linenrpath) or $fileopenerr = 1;
59
open (LINENR, "<".$linenrpath) or $fileopenerr = 1;
53
if ($fileopenerr == 0) {
60
if ($fileopenerr == 0) {
54
    $startAtLine = <LINENR>;
61
    $startAtLine = <LINENR>;
55
    if ($startAtLine =~ /\D/) {
62
    if ($startAtLine =~ /\D/) {
56
        print "Not a number\n";
63
        print "Not a number: $startAtLine\n";
57
        exit;
64
        exit;
58
    }
65
    }
59
    close(LINENR);
66
    close(LINENR);
60
} else {
67
} else {
61
    print "Could not open ".$linenrpath;
68
    print "Could not open ".$linenrpath;
62
    exit;
69
    exit;
63
}
70
}
64
 
71
 
65
$fileopenerr = 0;
72
$fileopenerr = 0;
66
open (CURRFILE, "<".$currentfilepath) or $fileopenerr = 1;
73
open (CURRFILE, "<".$currentfilepath) or $fileopenerr = 1;
67
if ($fileopenerr == 0) {
74
if ($fileopenerr == 0) {
68
    $currentfile = <CURRFILE>;
75
    $currentfile = <CURRFILE>;
Line 72... Line 79...
72
    }
79
    }
73
    close(CURRFILE);
80
    close(CURRFILE);
74
} else {
81
} else {
75
    print "Could not opeen ".$currentfilepath;
82
    print "Could not opeen ".$currentfilepath;
76
    if ($startAtLine != 0) {
83
    if ($startAtLine != 0) {
77
        exit;
84
        exit;
78
    }
85
    }
79
}
86
}
80
 
87
 
81
$fileopenerr = 0;
88
$fileopenerr = 0;
82
open (LOGFILE, "<".$logfilepath) or $fileopenerr = 1;
89
open (LOGFILE, "<".$logfilepath) or $fileopenerr = 1;
83
if ($fileopenerr == 1) {
90
if ($fileopenerr == 1) {
Line 103... Line 110...
103
while (<LOGFILE>) {
110
while (<LOGFILE>) {
104
    #print $linecnt ." ";
111
    #print $linecnt ." ";
105
    $line = $_;
112
    $line = $_;
106
    #$store = "";
113
    #$store = "";
107
    if ($linecnt >= $startAtLine) {
114
    if ($linecnt >= $startAtLine) {
108
        if ($line =~ m/^Session Time:/) {
115
        if ($line =~ m/^Session Time:/ || $line =~ m/^Session Start:/) {
109
            #print $line;
116
            #print $line;
110
            $datetimenice = $line;
117
            $datetimenice = $line;
111
            $datetimenice =~ s/Session Time: //g;
118
            $datetimenice =~ s/Session Time: //g;
-
 
119
            $datetimenice =~ s/Session Start: //g;
112
            $datetimenice =~ s/\n//g;
120
            $datetimenice =~ s/\n//g;
113
            $datetimenice =~ s/\r//g;
121
            $datetimenice =~ s/\r//g;
114
           
122
           
115
            $datetime = $line;
123
            $datetime = $line;
116
            $datetime =~ s/Session Time: //g;
124
            $datetime =~ s/Session Time: //g;
-
 
125
            $datetime =~ s/Session Start: //g;
117
            $datetime =~ s/://g;
126
            $datetime =~ s/://g;
118
            $datetime =~ s/\n//g;
127
            $datetime =~ s/\n//g;
119
            $datetime =~ s/\r//g;
128
            $datetime =~ s/\r//g;
120
            $datetime =~ s/ /_/g;
129
            $datetime =~ s/ /_/g;
121
            $datetime = lc($datetime);
130
            $datetime = lc($datetime);
122
 
131
 
123
            if ($currentfile) {
132
            if ($currentfile) {
124
                if ($debugmode == 0) {
133
                if ($debugmode == 0) {
125
                    print OUTFILE "\n\\\\\nNext page: [[".$datetime."]] \\\\ \n";
134
                    print OUTFILE "\n\\\\\nNext page: [[".$datetime."]] \\\\ \n";
126
                    print OUTFILE "Back to index: [[".$namespace."]] \\\\ \n";
135
                    print OUTFILE "Back to index: [[".$namespace."]] \\\\ \n";
-
 
136
                    close(OUTFILE);
127
                   
137
                   
-
 
138
                    $fileopenerr = 0;
-
 
139
                    copy($outputpath.$currentfile, $outputpath."yesterday.txt") or $fileopenerr = 1;
-
 
140
                    if ($fileopenerr == 1) {
-
 
141
                            print "Could not copy yesterday.txt-log";
-
 
142
                    }
128
                }              
143
                }              
129
            }
144
            }
130
 
145
 
131
            $currentfile = $datetime .".txt";
146
            $currentfile = $datetime .".txt";
132
            # skriv $datetimenice och $datetime till $contentspath
147
            # skriv $datetimenice och $datetime till $contentspath
133
            $fileopenerr = 0;
148
            $fileopenerr = 0;
134
            open (CONTENTSFILE, "<".$contentspath) or $fileopenerr = 1;
149
            open (CONTENTSFILE, "<".$contentspath) or $fileopenerr = 1;
135
            if ($fileopenerr == 0) {
150
            if ($fileopenerr == 0) {
136
                @contentsfilecontents = <CONTENTSFILE>;
151
                @contentsfilecontents = <CONTENTSFILE>;
137
                close(CONTENTSFILE);
152
                close(CONTENTSFILE);
138
                if ($debugmode == 0) {
153
                if ($debugmode == 0) {
139
                    open (CONTENTSFILE, ">".$contentspath) or $fileopenerr = 1;
154
                    open (CONTENTSFILE, ">".$contentspath) or $fileopenerr = 1;
140
                    if ($fileopenerr == 0) {
155
                    if ($fileopenerr == 0) {
141
                        print CONTENTSFILE "[[$namespace$datetime|$datetimenice]] \\\\ \n";
156
                        print CONTENTSFILE "[[$namespace$datetime|$datetimenice]] \\\\ \n";
142
                        foreach (@contentsfilecontents) {
157
                        foreach (@contentsfilecontents) {
143
                            print CONTENTSFILE $_;
158
                            print CONTENTSFILE $_;
144
                        }
159
                        }
145
                        close(CONTENTSFILE);
160
                        close(CONTENTSFILE);
146
                    }
161
                    }
147
                }
162
                }
148
            } else {
163
            } else {
149
                exit;
164
                exit;
150
            }
165
            }
151
 
166
 
152
            if ($debugmode == 0) {
167
            if ($debugmode == 0) {
153
                $fileopenerr = 0;
168
                $fileopenerr = 0;
154
                open (OUTFILE, ">>".$outputpath.$currentfile) or $fileopenerr = 1;
169
                open (OUTFILE, ">>".$outputpath.$currentfile) or $fileopenerr = 1;
155
                if ($fileopenerr == 1) {
170
                if ($fileopenerr == 1) {
156
                    print "Could not open ".$outputpath."/".$currentfile;
171
                    print "Could not open ".$outputpath."/".$currentfile;
157
                    exit;
172
                    exit;
158
                }
173
                }
159
            }
174
            }
160
            if ($currentfile) {
175
            if ($currentfile) {
161
                if ($debugmode == 0) {
176
                if ($debugmode == 0) {
162
                    print OUTFILE "====== ".$datetimenice." ======\n";
177
                    print OUTFILE "====== ".$datetimenice." ======\n";
163
                }              
178
                }              
164
            }
179
            }
165
            #print $datetime;
180
            #print $datetime;
166
        }
181
        }
167
       
182
       
168
        elsif ($currentfile) {
183
        elsif ($currentfile) {
169
            $parsedLine = $line;
184
            $parsedLine = $line;
170
            $parsedLine =~ s/\n//g;
185
            $parsedLine =~ s/\n//g;
171
            $parsedLine =~ s/\r//g;
186
            $parsedLine =~ s/\r//g;
172
            #$parsedLine = $parsedLine;
187
            #$parsedLine = $parsedLine;
Line 205... Line 220...
205
                #$color = "#$nickR$nickG$nickB";
220
                #$color = "#$nickR$nickG$nickB";
206
                $parsedLine =~ s/<$nick>/<color $colors[$nickVal]><$nick><\/color>/;
221
                $parsedLine =~ s/<$nick>/<color $colors[$nickVal]><$nick><\/color>/;
207
                #print $nick." ".$nickVal."\n";
222
                #print $nick." ".$nickVal."\n";
208
                #print $parsedLine ."\n";
223
                #print $parsedLine ."\n";
209
            }
224
            }
-
 
225
           
-
 
226
            #$parsedLine =~ s/\/\//\//g;
-
 
227
            $parsedLine =~ s/''/'/g;
-
 
228
            $parsedLine =~ s/\[\[/\[/g;
-
 
229
            $parsedLine =~ s/\]\]/\]/g;
-
 
230
            $parsedLine =~ s/\(\(/\(/g;
-
 
231
            $parsedLine =~ s/\)\)/\)/g;
-
 
232
            $parsedLine =~ s/____/_/g;
-
 
233
            $parsedLine =~ s/___/_/g;
-
 
234
            $parsedLine =~ s/__/_/g;
-
 
235
            $parsedLine =~ s/\*\*/\*/g;
210
           
236
 
211
            $parsedLine =~ s/\x{e5}/å/g;
237
            $parsedLine =~ s/\x{e5}/å/g;
212
            $parsedLine =~ s/\x{e4}/ä/g;
238
            $parsedLine =~ s/\x{e4}/ä/g;
213
            $parsedLine =~ s/\x{f6}/ö/g;
239
            $parsedLine =~ s/\x{f6}/ö/g;
214
            $parsedLine =~ s/\x{c5}/Å/g;
240
            $parsedLine =~ s/\x{c5}/Å/g;
215
            $parsedLine =~ s/\x{c4}/Ä/g;
241
            $parsedLine =~ s/\x{c4}/Ä/g;
216
            $parsedLine =~ s/\x{d6}/Ö/g;
242
            $parsedLine =~ s/\x{d6}/Ö/g;
217
 
243
 
218
            $parsedLine =~ s/\[wiki\]/**[wiki]**/g;
244
            $parsedLine =~ s/\[wiki\]/**[wiki]**/g;
219
            $parsedLine =~ s/\[svn\]/**[svn]**/g;
245
            $parsedLine =~ s/\[svn\]/**[svn]**/g;
220
 
246
 
221
            $parsedLine .= " ";
247
            $parsedLine .= " ";
222
            $parsedLine =~ s/http:\/\/projekt\.auml\.se\/(.+) /[[:$1]] /g;
248
            $parsedLine =~ s/http:\/\/projekt\.auml\.se\/(\S+)/[[:$1]] /g;
223
           
249
           
224
            $parsedLine .= "\\\\"."\n";
250
            $parsedLine .= "\\\\"."\n";
225
            if ($debugmode == 0) {
251
            if ($debugmode == 0) {
226
                print OUTFILE $parsedLine;
252
                print OUTFILE $parsedLine;
227
            }
253
            }
228
        }
254
        }
229
        #print $store;
255
        #print $store;
230
       
256
       
231
    }
257
    }
232
    $linecnt++;
258
    $linecnt++;
-
 
259
}
-
 
260
close(OUTFILE);
-
 
261
 
-
 
262
$fileopenerr = 0;
-
 
263
copy($outputpath.$currentfile, $outputpath."today.txt") or $fileopenerr = 1;
-
 
264
if ($fileopenerr == 1) {
-
 
265
    print "Could not copy today.txt-log";
233
}
266
}
234
 
267
 
235
if ($debugmode == 0) {
268
if ($debugmode == 0) {
236
    $fileopenerr = 0;
269
    $fileopenerr = 0;
237
    open (LINENR, ">".$linenrpath) or $fileopenerr = 1;
270
    open (LINENR, ">".$linenrpath) or $fileopenerr = 1;
Line 275... Line 308...
275
        exit;
308
        exit;
276
    }
309
    }
277
}
310
}
278
 
311
 
279
#print $linecnt-1 ." - ". $line;
312
#print $linecnt-1 ." - ". $line;
280
 
-
 
281
 
-
 
282
 
-
 
283
 
-
 
284
 
-
 
285
 
-
 
286
 
-