Skip to content

Instantly share code, notes, and snippets.

@mfojtik
Created November 8, 2011 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfojtik/1347852 to your computer and use it in GitHub Desktop.
Save mfojtik/1347852 to your computer and use it in GitHub Desktop.
Ruby course RSS scapper mail
require 'open-uri'
require 'nokogiri'
require 'pony'
#sudo gem install pony
module Course
class RSSSource
attr_accessor :url
attr_accessor :xml
def initialize(url)
self.url = url
self
end
def fetch!
f = open(url)
self.xml = Nokogiri::XML(f.read)
end
def titles
[]
end
end
class PlanetFedora < RSSSource
def initialize
super('http://planet.fedoraproject.org/rss20.xml')
@old_titles = []
self
end
def titles
titles_arr = []
self.xml.xpath('/rss/channel/item/title').each do |t|
next if @old_titles.include? t.text
yield t.text if block_given?
titles_arr << t.text
@old_titles << t.text
end
titles_arr
end
end
end
planet = Course::PlanetFedora.new
loop do
planet.fetch!
last_article = planet.titles.first
Pony.mail(
:from => 'mi@mifo.sk',
:to => 'mi@mifo.sk',
:subject => last_article
) unless last_article.nil?
sleep(5)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment