Now can optionally process text from replies

This commit is contained in:
Jacob Harris
2013-09-01 17:02:03 -04:00
parent 9fc7f7848b
commit c1764b48bf

View File

@@ -27,14 +27,20 @@ end
def filtered_tweets(tweets) def filtered_tweets(tweets)
include_urls = $include_urls || params["include_urls"] include_urls = $include_urls || params["include_urls"]
include_replies = $include_replies || params["include_replies"]
source_tweets = tweets.map {|t| t.text.gsub(/\b(RT|MT) .+/, '') } source_tweets = tweets.map {|t| t.text.gsub(/\b(RT|MT) .+/, '') }
if !include_urls if !include_urls
source_tweets = source_tweets.reject {|t| t =~ /(https?:\/\/)/ } source_tweets = source_tweets.reject {|t| t =~ /(https?:\/\/)/ }
end end
if !include_replies
source_tweets = source_tweets.reject {|t| t =~ /^@/ }
end
source_tweets.each do |t| source_tweets.each do |t|
t.gsub!(/(\#|(h\/t)|(http))\S+/, '') t.gsub!(/(\#|(h\/t)|(http))\S+/, '')
t.gsub!(/^(@[\d\w_]+\s?)+/, '')
t += "." if t !~ /[.?;:!]$/ t += "." if t !~ /[.?;:!]$/
end end
@@ -47,13 +53,13 @@ unless rand_key == 0 || params["force"]
else else
# Fetch a thousand tweets # Fetch a thousand tweets
begin begin
user_tweets = Twitter.user_timeline($source_account, :count => 200, :trim_user => true, :exclude_replies => true, :include_rts => false) user_tweets = Twitter.user_timeline($source_account, :count => 200, :trim_user => true, :exclude_replies => false, :include_rts => false)
max_id = user_tweets.last.id max_id = user_tweets.last.id
source_tweets += filtered_tweets(user_tweets) source_tweets += filtered_tweets(user_tweets)
# Twitter only returns up to 3200 of a user timeline, includes retweets. # Twitter only returns up to 3200 of a user timeline, includes retweets.
17.times do 17.times do
user_tweets = Twitter.user_timeline($source_account, :count => 200, :trim_user => true, :max_id => max_id - 1, :exclude_replies => true, :include_rts => false) user_tweets = Twitter.user_timeline($source_account, :count => 200, :trim_user => true, :max_id => max_id - 1, :exclude_replies => false, :include_rts => false)
puts "MAX_ID #{max_id} TWEETS: #{user_tweets.length}" puts "MAX_ID #{max_id} TWEETS: #{user_tweets.length}"
break if user_tweets.last.nil? break if user_tweets.last.nil?
max_id = user_tweets.last.id max_id = user_tweets.last.id
@@ -98,10 +104,10 @@ else
tweet_letters = tweet.gsub(/\P{Word}/, '') tweet_letters = tweet.gsub(/\P{Word}/, '')
next if source_tweets.any? {|t| t.gsub(/\P{Word}/, '') =~ /#{tweet_letters}/ } next if source_tweets.any? {|t| t.gsub(/\P{Word}/, '') =~ /#{tweet_letters}/ }
if rand(3) == 0 && tweet =~ /(in|to|from|for|with|by|our|of|your|around|under|beyond)\p{Space}\w+$/ # if rand(3) == 0 && tweet =~ /(in|to|from|for|with|by|our|of|your|around|under|beyond)\p{Space}\w+$/
puts "Losing last word randomly" # puts "Losing last word randomly"
tweet.gsub(/\p{Space}\p{Word}+.$/, '') # randomly losing the last word sometimes like horse_ebooks # tweet.gsub(/\p{Space}\p{Word}+.$/, '') # randomly losing the last word sometimes like horse_ebooks
end # end
if tweet.length < 40 && rand(10) == 0 if tweet.length < 40 && rand(10) == 0
puts "Short tweet. Adding another sentence randomly" puts "Short tweet. Adding another sentence randomly"