Skip to content

Commit

Permalink
Tweeting, debug is a bit nicer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake McGinty committed Mar 9, 2012
1 parent 03c48c4 commit 1b53478
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
19 changes: 7 additions & 12 deletions app.rb
Expand Up @@ -9,6 +9,8 @@
class TwitterBeats class TwitterBeats
@@debug = :high # PurdyPrint debug var @@debug = :high # PurdyPrint debug var




def initialize def initialize
pp :info, "TwitterBeats initializing..." pp :info, "TwitterBeats initializing..."
textmood = TwitterSentiment::Parser::TextMood.new :afinn textmood = TwitterSentiment::Parser::TextMood.new :afinn
Expand All @@ -18,13 +20,11 @@ def initialize
TwitterSentiment::Input::Twitter.new({ TwitterSentiment::Input::Twitter.new({
:status_callback => lambda { |status| :status_callback => lambda { |status|
weight, mood = {}, {} weight, mood = {}, {}
# text weight
pp :seperator pp :seperator
# text weight
text_score = textmood.score(status.text) text_score = textmood.score(status.text)
weight[:text] = text_score[:score] weight[:text] = text_score[:score]
mood[:text] = :bhargav mood [:text] = mood_from_score weight[:text]
mood[:text] = :happy if weight[:text] > 0
mood[:text] = :sad if weight[:text] < 0
pp mood[:text], "text score: #{weight[:text].to_s.ljust(7)}tweet: #{status.text}", :med pp mood[:text], "text score: #{weight[:text].to_s.ljust(7)}tweet: #{status.text}", :med


#user stalking #user stalking
Expand All @@ -33,15 +33,10 @@ def initialize
pp :info, "Followers per tweet: #{info[1]}" pp :info, "Followers per tweet: #{info[1]}"
weight[:description] = info[3][:score] weight[:description] = info[3][:score]
weight[:img] = info[2] weight[:img] = info[2]
mood[:description] = :bhargav mood[:description] = mood_from_score weight[:description]
mood[:description] = :happy if weight[:description] > 0 mood[:img] = mood_from_score weight[:img]
mood[:description] = :sad if weight[:description] < 0
mood[:img] = :bhargav
mood[:img] = :happy if weight[:img] > 0
mood[:img] = :sad if weight[:img] < 0
pp mood[:description], "Desc. score: #{weight[:description].to_s.ljust(8)}User description: #{status.user.description}" pp mood[:description], "Desc. score: #{weight[:description].to_s.ljust(8)}User description: #{status.user.description}"



#symbol checking #symbol checking
syms = random.symbol_count(status.text) syms = random.symbol_count(status.text)
pp :info, "syms: #{syms}" pp :info, "syms: #{syms}"
Expand Down Expand Up @@ -95,7 +90,7 @@ def initialize
} }
} #sentiment } #sentiment
} #data } #data
pp :info, "#{data}" pp :info, "#{data}", :high
output_send.send_gen data output_send.send_gen data
}, },
}) })
Expand Down
5 changes: 5 additions & 0 deletions lib/purdy-print.rb
Expand Up @@ -9,6 +9,11 @@ def level_to_score level
level = 3 if level == :high level = 3 if level == :high
return level return level
end 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 def pp mood=:info, msg="", debug_level=:off
moods = { moods = {
:info => Paint["[info] ", [50,50,50]], :info => Paint["[info] ", [50,50,50]],
Expand Down
1 change: 0 additions & 1 deletion lib/twitter-sentiment/output/send.rb
@@ -1,7 +1,6 @@
require 'json' require 'json'
require 'socket' require 'socket'
require 'rubygems' require 'rubygems'
require 'json'
require 'purdy-print' require 'purdy-print'
include PurdyPrint include PurdyPrint


Expand Down
8 changes: 4 additions & 4 deletions lib/twitter-sentiment/parser/text_mood.rb
Expand Up @@ -44,11 +44,11 @@ def initialize file
pb = ProgressBar.new "Dictionary", 3 # steps pb = ProgressBar.new "Dictionary", 3 # steps
pb.format = Paint["[info] ", [50,50,50]] + "%-#{@title_width}s %3d%% "+Paint["%s",:blue] pb.format = Paint["[info] ", [50,50,50]] + "%-#{@title_width}s %3d%% "+Paint["%s",:blue]
generate_dictionary File.open(file, "r") generate_dictionary File.open(file, "r")
pb.inc pb.inc # dictionary generated from text
generate_opposites generate_opposites
pb.inc pb.inc # opposites generated from dictionary in memory
generate_plurals generate_plurals
pb.inc pb.inc # plurals/anti-plurals generated from dictionary in mem
# done # done
pb.finish pb.finish
end end
Expand Down Expand Up @@ -89,7 +89,7 @@ def generate_plurals
end end
@dict.merge!(plurals) {|key,oldval,newval| oldval } @dict.merge!(plurals) {|key,oldval,newval| oldval }
end end
private :generate_plurals private :generate_plurals


# Turn a potentially poorly-formatted "tweet-like" message into an array of # 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, # words that would hopefully exist in a dictionary. This will never be perfect,
Expand Down

0 comments on commit 1b53478

Please sign in to comment.