Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a basic adium log parser

  • Loading branch information...
commit 92f772a4e37f9e6739bc6f417f2407fd810a9fcc 1 parent 7c63509
@jamesu authored
Showing with 112 additions and 2 deletions.
  1. +1 −1  core.rb
  2. +109 −0 parsers/adium_parser.rb
  3. +2 −1  whatyousay.rb
View
2  core.rb
@@ -17,7 +17,7 @@
end
# Parsers
-%w{parser bip_parser colloquy_parser ircii_parser talker_parser json_parser}.each do |parser|
+%w{parser bip_parser colloquy_parser ircii_parser talker_parser json_parser adium_parser}.each do |parser|
require File.join(File.dirname(__FILE__), "parsers/#{parser}")
end
View
109 parsers/adium_parser.rb
@@ -0,0 +1,109 @@
+class AdiumParser < Parser
+ # i.e. parses logs in ~/Library/Application Support/Adium 2.0/Users/Default/Logs/**.chatlog
+ STATUSTYPE_MAP = {
+ 'away' => :userAvailable,
+ 'return_away' => :userLeft,
+ 'online' => :userAvailable,
+ 'offline' => :userLeft,
+ 'idle' => nil,
+ 'return_idle' => nil,
+ 'away_message' => nil,
+ 'mobile' => nil,
+ 'return_mobile' => nil
+ }
+
+ EVENT_MAP = {
+ 'windowClosed' => :userDisconnected,
+ 'windowOpened' => :userAvailable
+ }
+
+ EVENT_DESC = {
+ 'windowClosed' => '[Closed the window]',
+ 'windowOpened' => '[Opened the window]'
+ }
+
+ # Format of adium logs:
+ # <chat>
+ # <status></status> ; <message></message> <action></action> ; <event></event>
+
+ HOSTMASK_MATCH = /([^@]+)@(.*)/
+
+ def initialize(collection)
+ super(collection)
+
+ @current_time = Time.now
+ @current_sender = nil
+ end
+
+ def parse(input)
+ data = Nokogiri::XML.parse(input.read)
+
+ chat_info = data.root
+ @collection.source = "#{chat_info['account']} #{chat_info['service']}"
+
+ # Parse XML
+ chat_info.xpath('*').each do |node|
+ event = parse_node(node)
+ unless event.nil?
+ if event.is_a?(Array)
+ event.each {|evt| @collection.add_event(evt)}
+ else
+ @collection.add_event(event)
+ end
+ end
+ end
+ end
+
+ def parse_node(entry)
+ time = Time.parse(entry['time']) rescue nil
+ sender = {:name => entry['alias']||entry['name'],
+ :ident => entry['sender'],
+ :alias => entry['name']||entry['alias'],
+ :hostmask => entry['sender']}
+
+ content = entry.inner_text
+ by = nil
+
+ case entry.name
+ when 'action'
+ # sender, time, [alias]
+ entry_type = :action
+
+ when 'message'
+ # sender, time, [alias]
+ entry_type = :message
+
+ when 'status'
+ # contact status
+ # type, sender, time
+ status_type = entry['type']
+ entry_type = :event
+ case status_type
+ when 'purple'
+ # leaving / joining room
+ entry_type = :event
+ else
+ # contact disconnection
+ entry_type = STATUSTYPE_MAP[entry['type']]||:event
+ end
+ when 'event'
+ # type= windowOpened, windowClosed,
+ entry_type = EVENT_MAP[entry['type']]||:event
+ content = EVENT_DESC[entry['type']]||''
+ type = :action
+ else
+ # Unknown
+ puts "Warning: unknown node #{entry.name}"
+ end
+
+ outs = {:type => entry_type,
+ :sender => sender,
+ :by => by,
+ :source => nil,
+ :occurred => time,
+ :content => content
+ }
+
+ outs
+ end
+end
View
3  whatyousay.rb
@@ -22,7 +22,8 @@
'bip' => BipParser,
'ircii' => IrciiParser,
'talker' => TalkerParser,
- 'json' => JSONParser
+ 'json' => JSONParser,
+ 'adium' => AdiumParser
}
def entry(logs)
Please sign in to comment.
Something went wrong with that request. Please try again.