-
Notifications
You must be signed in to change notification settings - Fork 3
/
send.rb
57 lines (55 loc) · 2.24 KB
/
send.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
require 'yajl'
require 'socket'
require 'rubygems'
require 'purdy-print'
include PurdyPrint
module TwitterSentiment
module Output
include PurdyPrint
class Send
def initialize
pp :info, "Send module initialized successfully."
end
# Sends data to the music generator
# @return [nil]
def send_gen weights, status, parsers
data = {
:input => {
:source => "twitter",
:username => status.user.screen_name,
:displayname => status.user.name,
:userid => status.user.id_str,
:url => "https://twitter.com/#!/" + status.user.screen_name + "/status/" + status.id_str + "/",
:userimgurl => status.user.profile_image_url.gsub(/_normal/, ''),
:raw_input => status.text,
:text => text_score[:stripped_text],
:metadata => nil #fix this
}, #input
:weights => weights, #weights
:sentiment => {
:text => {
:total_score => h, #stolen from "happiness"
:positive_score => nil, #fix this
:negative_score => nil #fix this
},
:tweet => {
:hash_obnoxiousess => status.entities.hashtags.length,
:retweet => status.retweeted
},
:face => {
:smiling => nil,
:confidence => nil,
}
} #sentiment
} #data
payload = Yajl::Encoder.encode(data)
prefs = TwitterSentiment::Prefs::Defaults.socket
streamSock = TCPSocket.new(prefs[:host], prefs[:port])
streamSock.write(payload)
streamSock.close
rescue Exception
pp :warn, "Failed to send payload across socket.", :med
end
end #Send
end #Output
end #TwitterSentiment