Permalink
Browse files

Tweeting, debug is a bit nicer.

  • Loading branch information...
1 parent 03c48c4 commit 1b534787fe20c6c865508fb4bb030b6875b7e599 Jake McGinty committed Mar 9, 2012
Showing with 16 additions and 17 deletions.
  1. +7 −12 app.rb
  2. +5 −0 lib/purdy-print.rb
  3. +0 −1 lib/twitter-sentiment/output/send.rb
  4. +4 −4 lib/twitter-sentiment/parser/text_mood.rb
View
19 app.rb
@@ -9,6 +9,8 @@
class TwitterBeats
@@debug = :high # PurdyPrint debug var
+
+
def initialize
pp :info, "TwitterBeats initializing..."
textmood = TwitterSentiment::Parser::TextMood.new :afinn
@@ -18,13 +20,11 @@ def initialize
TwitterSentiment::Input::Twitter.new({
:status_callback => lambda { |status|
weight, mood = {}, {}
- # text weight
pp :seperator
+ # text weight
text_score = textmood.score(status.text)
weight[:text] = text_score[:score]
- mood[:text] = :bhargav
- mood[:text] = :happy if weight[:text] > 0
- mood[:text] = :sad if weight[:text] < 0
+ mood [:text] = mood_from_score weight[:text]
pp mood[:text], "text score: #{weight[:text].to_s.ljust(7)}tweet: #{status.text}", :med
#user stalking
@@ -33,15 +33,10 @@ def initialize
pp :info, "Followers per tweet: #{info[1]}"
weight[:description] = info[3][:score]
weight[:img] = info[2]
- mood[:description] = :bhargav
- mood[:description] = :happy if weight[:description] > 0
- mood[:description] = :sad if weight[:description] < 0
- mood[:img] = :bhargav
- mood[:img] = :happy if weight[:img] > 0
- mood[:img] = :sad if weight[:img] < 0
+ mood[:description] = mood_from_score weight[:description]
+ mood[:img] = mood_from_score weight[:img]
pp mood[:description], "Desc. score: #{weight[:description].to_s.ljust(8)}User description: #{status.user.description}"
-
#symbol checking
syms = random.symbol_count(status.text)
pp :info, "syms: #{syms}"
@@ -95,7 +90,7 @@ def initialize
}
} #sentiment
} #data
- pp :info, "#{data}"
+ pp :info, "#{data}", :high
output_send.send_gen data
},
})
View
5 lib/purdy-print.rb
@@ -9,6 +9,11 @@ def level_to_score level
level = 3 if level == :high
return level
end
+ def mood_from_score score
+ :bhargav if score == 0
+ :happy if score > 0
+ :sad if score < 0
+ end
def pp mood=:info, msg="", debug_level=:off
moods = {
:info => Paint["[info] ", [50,50,50]],
View
1 lib/twitter-sentiment/output/send.rb
@@ -1,7 +1,6 @@
require 'json'
require 'socket'
require 'rubygems'
-require 'json'
require 'purdy-print'
include PurdyPrint
View
8 lib/twitter-sentiment/parser/text_mood.rb
@@ -44,11 +44,11 @@ def initialize file
pb = ProgressBar.new "Dictionary", 3 # steps
pb.format = Paint["[info] ", [50,50,50]] + "%-#{@title_width}s %3d%% "+Paint["%s",:blue]
generate_dictionary File.open(file, "r")
- pb.inc
+ pb.inc # dictionary generated from text
generate_opposites
- pb.inc
+ pb.inc # opposites generated from dictionary in memory
generate_plurals
- pb.inc
+ pb.inc # plurals/anti-plurals generated from dictionary in mem
# done
pb.finish
end
@@ -89,7 +89,7 @@ def generate_plurals
end
@dict.merge!(plurals) {|key,oldval,newval| oldval }
end
- private :generate_plurals
+ private :generate_plurals
# Turn a potentially poorly-formatted "tweet-like" message into an array of
# words that would hopefully exist in a dictionary. This will never be perfect,

0 comments on commit 1b53478

Please sign in to comment.