/ Published in: Ruby
Requires the twitter bundle. This is an early attempt at updating this. Pretty crude at the moment, but it works.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/env ruby require 'rubygems' require 'twitter' require 'net/http' require 'fileutils' require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb" COCOA_DIALOG = ENV['TM_SUPPORT_PATH'] + "/bin/CocoaDialog" CACHEDIR = ENV['HOME'] + '/Library/Caches/TwitterMonitor' FileUtils.mkdir_p CACHEDIR unless File.exist?(CACHEDIR) template = <<EOF # # Please fill in fields like this: # # email: [email protected] (username also works) # password: secret # email: password: EOF # ensure config file for twitter gem exists begin config = YAML::load open(ENV['HOME'] + "/.twitter") rescue open(ENV["HOME"] + '/.twitter','w').write(template) config = YAML::load open(ENV['HOME'] + "/.twitter") end # make sure there's actually account information in there if config == false or config.nil? or config['email'].nil? or config['password'].nil? res = %x{"#{COCOA_DIALOG}" ok-msgbox --no-newline --float \ --text "Please edit ~/.twitter to include your twitter email and password" \ --informative-text "Press OK to edit your ~/.twitter file in a new tab."} TextMate.exit_show_tool_tip("Cancelled!") if res == "2" `cygstart "txmt://open?url=file://#{ENV['HOME']}/.twitter"` end # attempt to retrieve statuses from friend timeline begin statuses = Twitter::Base.new(config['email'], config['password']).timeline rescue success = false end isEven = true bgStyle = "" statuses.select do |status| # ensure messages are suitable for display next if status.text.nil? || status.user.name.nil? status.text.gsub!(/"/, "'") #p status # try to find the most likely icon for this user icon = Dir.glob("#{CACHEDIR}/#{status.user.screen_name}.{gif,jpeg,jpg,png}").first # download and cache icons if nonexistant or over a month old unless icon and File.mtime(icon) > Time.now - 2629743.83 image = Net::HTTP.get(URI.parse(status.user.profile_image_url)) icon = CACHEDIR + "/" + status.user.screen_name + "." + status.user.profile_image_url.match(/\.(\w+)\?/)[1] icf = open(icon, "w") icf.write(image) icf.close end winicon = `cygpath -w #{icon}` # need to leave this out for TextMate. (isEven = !isEven) ? bgStyle = "background-color:#EEEEFF;" : bgStyle = "" puts "<p style='font-family:Helvetica,Arial,sans-serif; #{bgStyle}'><img src='file://#{winicon}' style='float:left' />#{status.user.name} (#{status.user.screen_name}):<br />#{status.text}</p>" end