Skip to content

Instantly share code, notes, and snippets.

@ashfurrow
Created December 3, 2015 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ashfurrow/c2449f0a159bf7a06357 to your computer and use it in GitHub Desktop.
Save ashfurrow/c2449f0a159bf7a06357 to your computer and use it in GitHub Desktop.
require 'nokogiri'
require 'open-uri'
require 'cgi'
episodes = Array.new
doc = Nokogiri::HTML(open("http://www.notificationcenter.tv/feed.rss"))
episodes = doc.xpath("//item")
episodes.reverse.each do |e|
title = e.xpath("title").map { |node| node.text.strip }.first
date = e.xpath("pubdate").map { |node| node.text.strip }.first
description = e.xpath("description").map { |node| node.text.strip }.first
audio = e.xpath("enclosure").map { |node| [node.attributes["url"], node.attributes["length"]] }.first
duration = e.xpath("duration").map { |node| CGI.unescapeHTML(node.text.strip) }.first
content = e.xpath("//encoded").map { |node| node.text.strip }.first
tree = Nokogiri::HTML(content)
anchors = tree.xpath("//li/a")
links = anchors.map { |node| [node.text, node.attributes["href"].to_s] }
puts "- title: #{title}"
puts " date: #{date}"
puts " audio: #{audio[0]}"
puts " file_length: #{audio[1]}"
puts " duration: \"#{duration}\""
puts " description: #{description}"
puts " links:"
puts links.map { |link| " - text: #{link[0]}\n href: #{link[1]}" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment