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
|
# File 'lib/stocktwit/rss.rb', line 7
def read
url = 'http://stocktwits.com/streams/all.xml'
xml_data = Net::HTTP.get_response(URI.parse(url)).body
doc = REXML::Document.new(xml_data)
= []
doc.elements.each('stream/tweets/tweet') do |el|
<< {
:user_id => el.elements['twitter_user_id'].text,
:status_id => el.elements['status_id'].text,
:tweet_datetime => el.elements['tweet_datetime'].text,
:twitter_username => el.elements['twitter_username'].text,
:tweet_text => el.elements['tweet_text'].text
}
end
tickers = {}
doc.elements.each('stream/tweets/tweet/stocks/stock/ticker') do |el|
unless tickers[el.text]
tickers[el.text] = 0
end
tickers[el.text] += 1
end
return {
:tweets => ,
:tickers => tickers.keys.collect {|k|
{:name => k, :count => tickers[k]}
}
}
end
|