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