citizen428.blog()

Try to learn something about everything

Ruby GitHub Projects Atom Feed

The other day I found an interesting post by Lisper extraordinaire Zach Beane on Planet Lisp, where he describes his program to generate a feed for the GitHub page about recently created Common Lisp repos.

Since good artists borrow and great artists steal, I decided to do the latter with his idea and implemented something similar for the new Ruby repos. It uses open-uri for fetching the page, Nokogiri for parsing it and Builder for generating the Atom feed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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

I’m hosting the feed on this blog (updated regularly via cron), add it to your feed reader to discover potentially interesting new Ruby projects.

Comments