Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'twitter'
- require 'simple-rss'
- require 'shorturl'
- require 'open-uri'
- ### Section 1
- username = 'your_username'
- password = 'your_password'
- twitter = Twitter::Base.new( username, password )
- ### Section 2
- # If the rss_times file exists, unmarshal
- # the rss_times hash, else create a new
- # one.
- rss_times = if File.exists?('rss_times')
- Marshal.load( File.read('rss_times') )
- else
- Hash.new( Time.mktime('1970') )
- end
- ### Section 3
- # Connect to twitter and fetch RSS
- rss = SimpleRSS.parse( open(ARGV[0]) )
- ### Section 4
- rss.items.reverse.each_with_index do|i,idx|
- if i.pubDate > rss_times[ARGV[0]]
- link = ShortURL.shorten(i.link)
- text = "#{i.title} #{link}"
- puts text
- puts "=" * 50
- ### Section 5
- # Save the time of this update
- # and marshal the hash back to storage
- twitter.update text
- rss_times[ARGV[0]] = i.pubDate
- File.open( 'rss_times', 'w' ) do|f|
- f.write Marshal.dump(rss_times)
- end
- sleep 300
- end
- end
Add Comment
Please, Sign In to add comment