stocktwit 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/stocktwit.rb +1 -1
- data/lib/stocktwit/rss.rb +45 -0
- data/lib/stocktwit/version.rb +1 -1
- metadata +4 -4
- data/lib/stocktwit/reader.rb +0 -9
data/lib/stocktwit.rb
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
require "stocktwit/
|
|
1
|
+
require "stocktwit/rss"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'rexml/document'
|
|
3
|
+
|
|
4
|
+
module Stocktwit
|
|
5
|
+
module Rss
|
|
6
|
+
class << self
|
|
7
|
+
def read
|
|
8
|
+
# StockTwits API URL (can be refreshed every minute or so)
|
|
9
|
+
url = 'http://stocktwits.com/streams/all.xml'
|
|
10
|
+
|
|
11
|
+
# get the XML data as a string
|
|
12
|
+
xml_data = Net::HTTP.get_response(URI.parse(url)).body
|
|
13
|
+
|
|
14
|
+
# extract event information
|
|
15
|
+
doc = REXML::Document.new(xml_data)
|
|
16
|
+
|
|
17
|
+
tweets = []
|
|
18
|
+
doc.elements.each('stream/tweets/tweet') do |el|
|
|
19
|
+
tweets << {
|
|
20
|
+
:user_id => el.elements['twitter_user_id'].text,
|
|
21
|
+
:status_id => el.elements['status_id'].text,
|
|
22
|
+
:tweet_datetime => el.elements['tweet_datetime'].text,
|
|
23
|
+
:twitter_username => el.elements['twitter_username'].text,
|
|
24
|
+
:tweet_text => el.elements['tweet_text'].text
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
tickers = {}
|
|
29
|
+
doc.elements.each('stream/tweets/tweet/stocks/stock/ticker') do |el|
|
|
30
|
+
unless tickers[el.text]
|
|
31
|
+
tickers[el.text] = 0
|
|
32
|
+
end
|
|
33
|
+
tickers[el.text] += 1
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
:tweets => tweets,
|
|
38
|
+
:tickers => tickers.keys.collect {|k|
|
|
39
|
+
{:name => k, :count => tickers[k]}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/stocktwit/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stocktwit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 23
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 0.0.
|
|
9
|
+
- 4
|
|
10
|
+
version: 0.0.4
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Christopher Scott
|
|
@@ -29,7 +29,7 @@ extensions: []
|
|
|
29
29
|
extra_rdoc_files: []
|
|
30
30
|
|
|
31
31
|
files:
|
|
32
|
-
- lib/stocktwit/
|
|
32
|
+
- lib/stocktwit/rss.rb
|
|
33
33
|
- lib/stocktwit/version.rb
|
|
34
34
|
- lib/stocktwit.rb
|
|
35
35
|
- LICENSE
|