daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest May 17th, 2018 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Post your direct messages from certain users as public tweets
  2. #
  3. # (ex) Broadcast DM's from tyler-durden and spacemonkey as user project-mayhem
  4. #
  5. #   $ ruby twitter_bot.rb project-mayhem:password tyler-durden spacemonkey
  6. #
  7. # Example Cron Entry:
  8. # */2 * * * * /usr/bin/ruby /home/foo/bin/retweet.rb project-mayhem:password tyler-durden spacemonkey
  9.  
  10. require 'rubygems'
  11. require 'yaml'
  12. require 'twitter'
  13.  
  14. CACHE = File.join(File.dirname(__FILE__), "twitter-bot.cache")
  15.  
  16. twit     = Twitter::Base.new *ARGV.shift.split(":")
  17. sources  = ARGV.dup
  18. dm_since = File.exist?(CACHE) ? IO.read(CACHE) : nil
  19. now      = nil
  20.  
  21. twit.direct_messages(dm_since).each do |message|
  22.   now ||= message.created_at
  23.   if sources.include?(message.sender_screen_name)
  24.     twit.post message.text.strip
  25.   end
  26. end
  27.  
  28. File.open CACHE, 'w' do |f|
  29.   f.write now
  30. end if now
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top