mirror of
https://github.com/thewesker/iron_ebooks.git
synced 2025-12-20 04:11:12 -05:00
Now can optionally process text from replies
This commit is contained in:
18
ebook.rb
18
ebook.rb
@@ -27,14 +27,20 @@ end
|
||||
|
||||
def filtered_tweets(tweets)
|
||||
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) .+/, '') }
|
||||
|
||||
if !include_urls
|
||||
source_tweets = source_tweets.reject {|t| t =~ /(https?:\/\/)/ }
|
||||
end
|
||||
|
||||
if !include_replies
|
||||
source_tweets = source_tweets.reject {|t| t =~ /^@/ }
|
||||
end
|
||||
|
||||
source_tweets.each do |t|
|
||||
t.gsub!(/(\#|(h\/t)|(http))\S+/, '')
|
||||
t.gsub!(/^(@[\d\w_]+\s?)+/, '')
|
||||
t += "." if t !~ /[.?;:!]$/
|
||||
end
|
||||
|
||||
@@ -47,13 +53,13 @@ unless rand_key == 0 || params["force"]
|
||||
else
|
||||
# Fetch a thousand tweets
|
||||
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
|
||||
source_tweets += filtered_tweets(user_tweets)
|
||||
|
||||
# Twitter only returns up to 3200 of a user timeline, includes retweets.
|
||||
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}"
|
||||
break if user_tweets.last.nil?
|
||||
max_id = user_tweets.last.id
|
||||
@@ -98,10 +104,10 @@ else
|
||||
tweet_letters = tweet.gsub(/\P{Word}/, '')
|
||||
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+$/
|
||||
puts "Losing last word randomly"
|
||||
tweet.gsub(/\p{Space}\p{Word}+.$/, '') # randomly losing the last word sometimes like horse_ebooks
|
||||
end
|
||||
# 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"
|
||||
# tweet.gsub(/\p{Space}\p{Word}+.$/, '') # randomly losing the last word sometimes like horse_ebooks
|
||||
# end
|
||||
|
||||
if tweet.length < 40 && rand(10) == 0
|
||||
puts "Short tweet. Adding another sentence randomly"
|
||||
|
||||
Reference in New Issue
Block a user