Subversion Repositories HomeAutomation

Rev

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