# twitter.rb $Revision: 1.1 $ # Copyright (C) 2007 Michitaka Ohno # You can redistribute it and/or modify it under GPL2. require 'timeout' require 'time' require 'open-uri' require 'rexml/document' @twitter_statuses = [] if /^(latest|day)$/ =~ @mode then add_header_proc do xml = nil timeout( 5 ) do begin xml = open( "http://twitter.com/statuses/user_timeline/#{@conf['twitter.user']}.xml" ){|f| f.read} rescue Exception end end doc = REXML::Document.new( xml ).root if xml if doc then doc.elements.each( 'status' ) do |e| @twitter_statuses << [@conf.to_native( e.elements['text'].text ), Time.parse( e.elements['created_at'].text ).localtime] end end '' end end add_body_leave_proc do |date| today_statuses = [] @twitter_statuses.each do |t, d| today_statuses << [t, d] if d.to_a[3,3] == date.to_a[3,3] end if !today_statuses.empty? r = %Q[
] r << %Q[

Twitter statuses

] today_statuses.sort{|a, b| b.last<=>a.last}.each do |t, d| r << %Q[

#{CGI::escapeHTML( t )} (#{d.strftime( '%H:%M:%S' )})

] end r << %Q[
] else '' end end