Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

JSON parsing and socket output functionality added

  • Loading branch information...
commit c956fa96a4b8c0ac1bfcf9da8a7c4902193b5282 1 parent a3f7f6d
@scowalt scowalt authored
View
48 app.rb
@@ -13,10 +13,10 @@ def initialize
textmood = TwitterSentiment::Parser::TextMood.new :afinn
facerecon = TwitterSentiment::Parser::FaceRecon.new
userinfo = TwitterSentiment::Parser::UserInfo.new
+ output_send = TwitterSentiment::Output::Send.new
TwitterSentiment::Input::Twitter.new({
:status_callback => lambda { |status|
weight, mood = {}, {}
- pp :info, "NEW TWEET"
# text weight
pp :seperator
weight[:text] = textmood.score(status.text)
@@ -41,10 +41,50 @@ def initialize
info = userinfo.gather(status.user)
pp :info, "Boring images: #{info[0]}"
pp :info, "Followers per tweet: #{info[1]}"
+ weight[:description] = info[3]
mood[:description] = :bhargav
- mood[:description] = :happy if info[3] > 0
- mood[:description] = :sad if info[3] < 0
- pp mood[:description], "Desc. score: #{info[3].to_s.ljust(8)}User description: #{status.user.description}"
+ mood[:description] = :happy if weight[:description] > 0
+ mood[:description] = :sad if weight[:description] < 0
+ pp mood[:description], "Desc. score: #{weight[:description].to_s.ljust(8)}User description: #{status.user.description}"
+
+ #compile data (not JSON)
+ #put this is a separate method?
+ total_happiness = Integer(weight[:text]) + Integer(weight[:img]) + Integer(weight[:description])
+ 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" => imgurl,
+ "raw_input" => status.text,
+ "text" => nil, #fix this
+ "metadata" => nil #fix this
+ }, #input
+ "weights" => {
+ "happiness" => total_happiness, #filler algorithm
+ "excitement" => info[1] - info[0], #filler algorithm
+ "randomness" => rand(20) - 10 #literally random
+ }, #weights
+ "sentiment" => {
+ "text" => {
+ "total_score" => total_happiness, #stolen from "happiness"
+ "positive_score" => nil, #fix this
+ "negative_score" => nil #fix this
+ },
+ "tweet" => {
+ "hash_obnoxiousess" => status.entities.hashtags.length, #fix this
+ "retweet" => status.retweeted
+ },
+ "face" => {
+ "smiling" => nil,
+ "confidence" => nil,
+ }
+ } #sentiment
+ } #data
+ pp :info, "#{data}"
+ output_send.send_gen data
},
})
end
View
27 lib/twitter-sentiment/output/send.rb
@@ -0,0 +1,27 @@
+require 'json'
+require 'socket'
+require 'rubygems'
+require 'json'
+require 'purdy-print'
+include PurdyPrint
+
+module TwitterSentiment
+ module Output
+ include PurdyPrint #is this redundant?
+ class Send
+ def initialize
+ pp :info, "Send module initialized successfully."
+ end
+
+ # Sends data to the music generator
+ # @param [Array] Data in pre-defined form (not in JSON)
+ # @return [nil]
+ def send_gen data = nil
+ payload = data.to_json
+ streamSock = TCPSocket.new( "127.0.0.1", 9133 )
+ streamSock.write(payload)
+ streamSock.close
+ end
+ end #Send
+ end #Output
+end #TwitterSentiment
View
3  lib/twitter-sentiment/parser/face_recon.rb
@@ -4,7 +4,7 @@
module TwitterSentiment
module Parser
- include PurdyPrint
+ include PurdyPrint #is this redundant?
class FaceRecon
def initialize
@@ -52,6 +52,7 @@ def profile_image_happiness img = nil
end
score.to_f / arr.length.to_f
end # if != nil
+ 0
end
end # FaceRecon
end # Parser
View
2  lib/twitter-sentiment/prefs/defaults.rb
@@ -30,7 +30,7 @@ def self.twitter
{
:user_id => 480959867,
:user_name => 'sigmusic_uiuc',
- :search_phrase => "#YouProbablyShouldnt",
+ :search_phrase => "#MyFavoriteText",
}
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.