#!/usr/bin/env ruby # ############################################################# # # author: mathias gumz # date : Fre 08 Aug 2003 03:16:57 CEST # file : fluxstats # about : # ############################################################# # # # Copyright (c) 2003 Mathias Gumz # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # require 'date' require 'getoptlong' HELP = < END def convertlog(filename, ignore) lastdate= "" IO.foreach(filename) { |line| date, time, chk1, chk1, mesg= line.unpack('@1a11a8aaa*') ho, mi, se= time.split(/:/) if date != lastdate then lastdate= date ye, mo, da= date.split(/\//) d= Date.new(ye.to_i, mo.to_i, da.to_i) puts "--- Log opened #{Date::ABBR_DAYNAMES[d.wday]} #{Date::ABBR_MONTHNAMES[d.month]} #{d.day} [#{ho}:#{mi}]:#{se} #{d.year}" end case mesg when /^@(.*)/ msg= $1 case msg when /joined channel/ puts "[#{ho}:#{mi}] *** #{msg.sub!(/channel /, '').sub!(/joined/, '(unknown) has joined').strip!}" when /Quit:/ puts "[#{ho}:#{mi}] *** #{msg.split(/:/)[1].strip!} has quit" when /set topic/ puts "[#{ho}:#{mi}] *** #{msg.sub!(/set topic /, 'changes topic to').strip!}" when /has been kicked/ #puts "[#{ho}:#{mi}] *** #{msg.sub!(/has beend kicked/, 'was kicked')}" puts "[#{ho}:#{mi}] *** #{msg.strip!}" when /is now known/ puts "[#{ho}:#{mi}] *** #{msg.strip!}" end when /^<(.*?)>(.*)/ nick, msg= $1, $2 if nick != ignore puts "[#{ho}:#{mi}] <#{nick}>#{msg}" end end } end begin parser = GetoptLong.new parser.set_options( [ "--ignore", "-i", GetoptLong::REQUIRED_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ] ) ignore= "" parser.each do |opt, arg| case opt when "--help" puts HELP exit 0 when "--ignore" ignore= arg end end if ARGV.length < 1 puts "need a logfile" exit 1 end convertlog(ARGV.shift, ignore) end # # # ############################################################# # # #############################################################