Created
November 8, 2011 14:24
-
-
Save mfojtik/1347852 to your computer and use it in GitHub Desktop.
Ruby course RSS scapper mail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => '[email protected]', | |
:to => '[email protected]', | |
: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