Skip to content

Instantly share code, notes, and snippets.

@mjmsmith
Created September 5, 2014 02:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjmsmith/fce12ff3997e3f292307 to your computer and use it in GitHub Desktop.
Save mjmsmith/fce12ff3997e3f292307 to your computer and use it in GitHub Desktop.
WWDC videos
require "date"
require "nokogiri"
require "open-uri"
builder = Nokogiri::XML::Builder.new do |xml|
xml.feed ({"xml:lang"=>"en-US", "xmlns"=>"http://www.w3.org/2005/Atom"}) {
xml.id "http://camazotz.com/wwdc.xml"
xml.link ({"rel"=>"self", "href"=>"http://camazotz.com/wwdc/index.xml"})
xml.link ({"rel"=>"alternate", "type"=>"text/html", "href"=>"https://developer.apple.com/videos/wwdc/"})
xml.title "WWDC Videos"
xml.updated DateTime.now.rfc3339
for year in 2010..2014
url = "https://developer.apple.com/videos/wwdc/#{year}/"
html = Nokogiri::HTML(open(url))
for e in html.xpath("//li[@class='session']") do
video_id = e.attr("id").split("-")[0]
time = DateTime.rfc3339("#{year}-06-01T12:00:00Z") + Rational(video_id, 86400)
video_title_node = (e.xpath(".//li[@class='thumbnail-title']") || []).first
video_desc_node = (e.xpath(".//div[@class='description active']/p") || []).first
video_url_node = (e.xpath(".//p[@class='download']/a/@href") || []).first
if video_title_node && video_desc_node && video_url_node then
xml.entry {
xml.id "tag:camazotz.com,#{year}:/wwdc/#{video_id}"
xml.author { xml.name "Apple" }
xml.published time.rfc3339
xml.updated time.rfc3339
xml.title "#{year}.#{video_id} #{video_title_node.text}"
xml.content ({"type"=>"text"}) { xml.text video_desc_node.text }
xml.link ({"rel"=>"alternate", "type"=>"text/html", "href"=>"#{url}##{video_id}"})
xml.link ({"rel"=>"enclosure", "type"=>"video/mp4", "href"=>video_url_node.text})
}
end
end
end
}
end
puts builder.to_xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment