Created
February 11, 2013 12:40
-
-
Save mindreframer/4754214 to your computer and use it in GitHub Desktop.
create HTML-page from Deutsche Welle Audio Course
This file contains hidden or 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
#!/usr/bin/env ruby | |
# encoding: UTF-8 | |
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
url = "http://rss.dw.de/xml/DKpodcast_audiotrainer_de" | |
filename = "DKpodcast_audiotrainer_de" | |
unless File.exists?(filename) | |
`wget #{url}` | |
end | |
xml = Nokogiri::XML(File.read(filename)) | |
def remove_html(args) | |
args.map do |e| | |
e.to_s.gsub(%r{</?[^>]+?>}, '') | |
end | |
end | |
titles = remove_html(xml.search("//title").reverse) | |
links = remove_html(xml.search("//link").reverse) | |
descriptions = remove_html(xml.search("//description").reverse) | |
template = <<-TEMPLATE | |
<div> | |
<a href="@@link@@">@@title@@</a> | |
@@descriptions@@ | |
</div> | |
TEMPLATE | |
templates = titles.size.times.map do |i| | |
template. | |
gsub("@@descriptions@@", descriptions[i]). | |
gsub("@@link@@", links[i]). | |
gsub("@@title@@", titles[i]) | |
end | |
html = <<-HTML | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<title></title> | |
</head> | |
<body> | |
@@content@@ | |
</body> | |
</html> | |
HTML | |
puts html.gsub("@@content@@", templates.join("\n")) | |
# write the output of this string to a file | |
# ruby dw_audio_course_rss_feed_to_html.rb > dw_audio_links.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment