gist: 2538 Download_button fork
public
Description:
Watch your keywords appear on the twitter stream
Public Clone URL: git://gist.github.com/2538.git
tweet_beat.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#
# 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

Owner

tamalw

Revisions

  • 0b28cb firblitz Fri Jul 25 15:18:14 -0700 2008
  • 2a17a1 firblitz Fri Jul 25 15:10:08 -0700 2008