Sha256: af8df45e248e33e6ac1de7d2809aeaf6e1cac45fafcfb0bc97790738208d465a

Contents?: true

Size: 1.21 KB

Versions: 23

Compression:

Stored size: 1.21 KB

Contents

# twitter.rb $Revision: 1.1 $
# Copyright (C) 2007 Michitaka Ohno <elpeo@mars.dti.ne.jp>
# 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.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[<div class="section">]
		r << %Q[<h3><a href="http://twitter.com/#{@conf['twitter.user']}">Twitter statuses</a></h3>]
		today_statuses.sort{|a, b| b.last<=>a.last}.each do |t, d|
			r << %Q[<p><strong>#{CGI::escapeHTML( t )}</strong> (#{d.strftime( '%H:%M:%S' )})</p>]
		end
		r << %Q[</div>]
	else
		''
	end
end

Version data entries

23 entries across 19 versions & 2 rubygems

Version Path
tdiary-contrib-5.1.2 plugin/twitter.rb
tdiary-contrib-5.1.1 plugin/twitter.rb
tdiary-contrib-5.1.0 plugin/twitter.rb
tdiary-contrib-5.0.13 plugin/twitter.rb
tdiary-contrib-5.0.12 plugin/twitter.rb
tdiary-contrib-5.0.11 plugin/twitter.rb
tdiary-contrib-5.0.10 plugin/twitter.rb
tdiary-contrib-5.0.9 plugin/twitter.rb
tdiary-contrib-5.0.8 plugin/twitter.rb
tdiary-contrib-5.0.7 plugin/twitter.rb
tdiary-contrib-5.0.6 plugin/twitter.rb
tdiary-contrib-5.0.5 plugin/twitter.rb
tdiary-5.0.5 vendor/bundle/bundler/gems/tdiary-contrib-fa9c20aa0d97/plugin/twitter.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/bundler/gems/tdiary-contrib-8299b30cbf3f/plugin/twitter.rb
tdiary-5.0.5 vendor/bundle/bundler/gems/tdiary-contrib-f08988dfa0f6/plugin/twitter.rb
tdiary-5.0.5 vendor/bundle/bundler/gems/tdiary-contrib-a3c5f37278c4/plugin/twitter.rb
tdiary-5.0.5 vendor/bundle/bundler/gems/tdiary-contrib-8299b30cbf3f/plugin/twitter.rb
tdiary-contrib-5.0.4 plugin/twitter.rb
tdiary-5.0.4 vendor/bundle/bundler/gems/tdiary-contrib-8299b30cbf3f/plugin/twitter.rb
tdiary-contrib-5.0.3 plugin/twitter.rb