# # tweet_beat.rb # ShoesFest 2008 # # Created by Tamal White on 2008-07-25. # Copyright 2008 Tamal White. All rights reserved. # require 'hpricot' Shoes.app :width => 800, :height => 600, :margin => 10 do @words = ["shoes", "socks", "boots", "toes"] @add_new_line = lambda do |slot,words,tweet,animate| words.each do |word| tweet[:text].gsub!(/#{word}/i) { |w| "◊#{w}◊" } end banana_split = tweet[:text].split("◊") bowl = [] banana_split.each_with_index do |bananas,i| if i % 2 == 0 bowl << bananas else bowl << strong(bananas, :stroke => chocolate, :size => 36) end end slot.prepend do new_yummy = stack do tagline bowl, :stroke => slateblue inscription link("— #{tweet[:author].downcase}", :click => tweet[:link], :stroke => orangered) end if animate shake = animate do |i| new_yummy.displace((Math.sin(i) * 12).to_i, 0) end timer(2) do shake.stop new_yummy.displace(0, 0) end end end end @search_twitter = lambda do |words| doc = Hpricot.XML(open("http://search.twitter.com/search.atom?q=#{words * '%20OR%20'}#{'&since_id=' + @since_id unless @since_id.nil?}")) nest = [] (doc/:entry).each_with_index do |entry, i| @since_id = (entry/:id).inner_html.split(":").last if i == 0 birdy_tweet_tweet = {} birdy_tweet_tweet[:text] = (entry/:title).inner_text birdy_tweet_tweet[:author] = (entry/:author/:uri).inner_html.scan(/http:\/\/twitter\.com\/(.*)/).flatten.first birdy_tweet_tweet[:link] = (entry/:link).first["href"] nest << birdy_tweet_tweet end nest.reverse end background black @custom_wordies = edit_line :width => 400 @custom_wordies.text = @words.join(" ") button "Set keywords" do @words = @custom_wordies.text.to_s.split @since_id = nil @search_twitter.call(@words).each do |tweet| @add_new_line.call(@slot, @words, tweet, false) end end @slot = flow @search_twitter.call(@words).each do |tweet| @add_new_line.call(@slot, @words, tweet, false) end every(10) do @search_twitter.call(@words).each do |tweet| @add_new_line.call(@slot, @words, tweet, true) end if @slot.contents.length > 30 @slot.contents[31...@slot.contents.length].each do |e| e.remove end end end end