Sha256: 6411912af109f0f4d4934fdaee6c2798a08bb25282e58468ba0ced309d1b8112

Contents?: true

Size: 1.2 KB

Versions: 15

Compression:

Stored size: 1.2 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( 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

15 entries across 14 versions & 2 rubygems

Version Path
tdiary-contrib-4.2.1 plugin/twitter.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/bundler/gems/tdiary-contrib-d189eb6688f1/plugin/twitter.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/bundler/gems/tdiary-contrib-2ab36447ae2a/plugin/twitter.rb
tdiary-contrib-4.2.0 plugin/twitter.rb
tdiary-contrib-4.1.3 plugin/twitter.rb
tdiary-contrib-4.1.2 plugin/twitter.rb
tdiary-contrib-4.1.1 plugin/twitter.rb
tdiary-contrib-4.1.0 plugin/twitter.rb
tdiary-contrib-4.0.5.1 plugin/twitter.rb
tdiary-contrib-4.0.4 plugin/twitter.rb
tdiary-contrib-4.0.3 plugin/twitter.rb
tdiary-contrib-4.0.2.1 plugin/twitter.rb
tdiary-contrib-4.0.2 plugin/twitter.rb
tdiary-contrib-3.2.2.20130614 plugin/twitter.rb
tdiary-contrib-3.2.2.20130518 plugin/twitter.rb