Skip to content
Browse files

Merged changes for app.rb

  • Loading branch information...
2 parents a7d1594 + 7d8f8ee commit 4e0c08705168993aa31f36e7dc605b6c293c3de2 Jake McGinty committed Mar 4, 2012
View
10 app.rb
@@ -12,9 +12,11 @@ def initialize
pp :info, "TwitterBeats initializing..."
textmood = TwitterSentiment::Parser::TextMood.new :afinn
facerecon = TwitterSentiment::Parser::FaceRecon.new
+ userinfo = TwitterSentiment::Parser::UserInfo.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)
@@ -35,6 +37,14 @@ def initialize
pp :warn, "failed to download profile image, so cannot calculate face weight"
mood[:img] = 0.0
end
+ #user stalking
+ info = userinfo.gather(status.user)
+ pp :info, "Boring images: #{info[0]}"
+ pp :info, "Followers per tweet: #{info[1]}"
+ mood[:description] = :bhargav
+ mood[:description] = :happy if info[2] > 0
+ mood[:description] = :sad if info[2] < 0
+ pp mood[:description], "Description score: #{info[2]}; User description: #{status.user.description}"
},
})
end
View
1 lib/twitter-sentiment/input/face_recon.rb
@@ -1,6 +1,7 @@
require 'face'
require 'twitter-sentiment/prefs/secrets'
require 'purdy-print'
+include PurdyPrint
module TwitterSentiment
module Input
View
1 lib/twitter-sentiment/parser/face_recon.rb
@@ -1,5 +1,6 @@
require 'twitter-sentiment/input/face_recon.rb'
require 'purdy-print'
+include PurdyPrint
module TwitterSentiment
module Parser
View
2 lib/twitter-sentiment/parser/text_mood.rb
@@ -101,7 +101,7 @@ def sentence_to_stripped_array sentence
# Returns the mood score of the string.
#
- # @param [String] word to search for
+ # @param [String] string to score
# @return [Integer,nil] the score of the sentence passed in
def score sentence
words = sentence_to_stripped_array sentence
View
27 lib/twitter-sentiment/parser/user_info.rb
@@ -1,23 +1,36 @@
+require 'purdy-print'
require 'twitter-sentiment/parser/face_recon'
+require 'twitter-sentiment/parser/text_mood'
module TwitterSentiment
module Parser
class UserInfo
- #@param [Twitter::User] the user in question
+ def initialize
+ pp :info, "User info parser initialized successfully."
+ @textmood = TwitterSentiment::Parser::TextMood.new :afinn
+ @facerecon = TwitterSentiment::Parser::FaceRecon.new
+ end
+
+ #@param [Twitter::User] the user in question
#@return data about the user
def gather user
#Call all of the included methods
- boringImages = defaultImgs(user.profile_background_image_url, user.profile_image_url) #int
- followPerTweet = user.followers_count.to_f / user.statuses_count.to_f #float
- profHappiness = FaceRecon.profileImageHappiness(user.profile_image_url) #float
-
- #Spit out data in some format
+ if user != nil
+ boringImages = default_imgs(user.profile_background_image_url, user.profile_image_url) #int
+ followPerTweet = user.followers_count.to_f / user.statuses_count.to_f #float, 0...
+ profHappiness = @facerecon.profile_image_happiness(user.profile_image_url) #int, -100...100
+ descriptionScore = @textmood.score(user.description) #int
+
+ #Spit out data in some format
+ return [boringImages, followPerTweet, profHappiness, descriptionScore]
+ end
+ return [0,0,0,0] if user == nil
end
#@param [String] Image url of user background image
#@param [String] Image url of user profile image
#@return [int] number of images that are default
- def defaultImgs back = nil, prof = nil
+ def default_imgs back = nil, prof = nil
r = 0
r += 1 if back.index("twimg.com/images/themes/") != nil
r += 1 if prof.index("twimg.com/sticky/default_profile_images/") != nil

0 comments on commit 4e0c087

Please sign in to comment.
Something went wrong with that request. Please try again.