Created
November 23, 2011 19:33
-
-
Save citizen428/1389652 to your computer and use it in GitHub Desktop.
Create an Atom feed from the new Ruby repos page
This file contains 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 'builder' | |
html = open("https://github.com/languages/Ruby/created") | |
doc = Nokogiri::HTML.parse(html) | |
atom = Builder::XmlMarkup.new(:target => STDOUT, :indent => 2) | |
atom.instruct! | |
atom.feed "xmlns" => "http://www.w3.org/2005/Atom" do | |
atom.id "urn:citizen428:github:newrepos" | |
atom.updated Time.now.utc.iso8601(0) | |
atom.title "New GitHub Ruby Repos", :type => "text" | |
atom.link :rel => "self", :href => "/ruby_github.atom" | |
doc.xpath("//table[@class='repo']/tr/td[@class='title']/a").each do |title| | |
name = title.content | |
owner = title.at_xpath("../../td[@class='owner']/a").content | |
desc = title.at_xpath("../../following-sibling::tr/td[@class='desc']").content | |
date = Time.parse(title.at_xpath("../../td[@class='date']").content) | |
atom.entry do | |
atom.title "#{owner}: #{name}" | |
atom.author { atom.name owner } | |
atom.link "href" => "https://github.com#{title.attributes["href"].value}" | |
atom.id "urn:citizen428:github:#{owner}:#{name}" | |
atom.published date.utc.iso8601(0) | |
atom.updated date.utc.iso8601(0) | |
atom.content desc, :type => "html" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment