Guest User

Untitled

a guest
Jul 2nd, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. require 'rubygems'
  2. require 'twitter'
  3. require 'simple-rss'
  4. require 'shorturl'
  5. require 'open-uri'
  6.  
  7. ### Section 1
  8. username = 'your_username'
  9. password = 'your_password'
  10. twitter = Twitter::Base.new( username, password )
  11.  
  12. ### Section 2
  13. # If the rss_times file exists, unmarshal
  14. # the rss_times hash, else create a new
  15. # one.
  16. rss_times = if File.exists?('rss_times')
  17. Marshal.load( File.read('rss_times') )
  18. else
  19. Hash.new( Time.mktime('1970') )
  20. end
  21.  
  22. ### Section 3
  23. # Connect to twitter and fetch RSS
  24. rss = SimpleRSS.parse( open(ARGV[0]) )
  25.  
  26. ### Section 4
  27. rss.items.reverse.each_with_index do|i,idx|
  28. if i.pubDate > rss_times[ARGV[0]]
  29. link = ShortURL.shorten(i.link)
  30. text = "#{i.title} #{link}"
  31.  
  32. puts text
  33. puts "=" * 50
  34.  
  35. ### Section 5
  36. # Save the time of this update
  37. # and marshal the hash back to storage
  38.  
  39. twitter.update text
  40.  
  41. rss_times[ARGV[0]] = i.pubDate
  42. File.open( 'rss_times', 'w' ) do|f|
  43. f.write Marshal.dump(rss_times)
  44. end
  45.  
  46. sleep 300
  47. end
  48. end
Add Comment
Please, Sign In to add comment