Skip to content

Instantly share code, notes, and snippets.

@iannono
Created August 15, 2013 06:21
Show Gist options
  • Save iannono/6238683 to your computer and use it in GitHub Desktop.
Save iannono/6238683 to your computer and use it in GitHub Desktop.
fetch asciicast from railscast.com
#!/usr/bin/env ruby
##encoding:utf-8
require 'open-uri'
require 'nokogiri'
require 'stringio'
def generate_cast_url(link)
link + "?view=asciicast"
end
def fetch_ascii_content(cast_url)
cast_content = Nokogiri::HTML(open(cast_url))
cast_content.css('.asciicast').inner_html()
end
def generate_file_name(cast_url)
cast_url.slice(/\/\d+.*\?/).gsub(/[\/\?]/,'') + '.html'
end
def generate_asciicast_doc(link)
cast_url = generate_cast_url(link)
file_name = generate_file_name(cast_url)
content = fetch_ascii_content(cast_url)
File.open(file_name, "w") do |file|
file.puts content
end
end
rss_url = 'http://railscasts.com/subscriptions/WbnCA6UR0xak0TrMUSaGQg/episodes.rss'
rss_doc = Nokogiri::XML(open(rss_url))
rss_doc.css('item link').each do |link|
generate_asciicast_doc(link.text)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment