1
0
Fork 0

Better feed now

This commit is contained in:
neingeist 2006-10-13 21:02:35 +00:00
parent f5b07db285
commit d0ffc55b65
3 changed files with 46 additions and 9 deletions

View file

@ -16,6 +16,7 @@ require "#{$0}.templates.rb"
#----------------------------------------------------------------------------
# Some helper functions
# Get HEAD info from an URL
def head(url)
uri = URI.parse(url)
@ -24,6 +25,16 @@ def head(url)
end
end
# Q&D text-to-html
def to_html(text)
html = text.clone
html.gsub!(/(http:\/\/\S*)/, '<a href="\1">\1</a>')
html.gsub!(/\n/, "<br/>")
html
end
#----------------------------------------------------------------------------
# Get episodes from wiki
@ -34,19 +45,26 @@ episodes = []
@wiki.article(template).what_links_here.each do |page|
# puts page # DEBUG
if erste_sendung = parse_template(page, template)["erste_sendung"]
episode_info = parse_template(page, template)
if erste_sendung = episode_info["erste_sendung"]
episode = {
"title" => page,
"url" => @wiki.full_article_url(page),
"discussion" => @wiki.full_article_url("Diskussion:#{page}"),
"enclosure_url" => parse_template(page, template)["download"],
"enclosure_url" => episode_info["download"].chomp,
"date" => Date.today(), # fallback
"description" => episode_info["beschreibung"] || "",
"summary" => episode_info["beschreibung"] || "",
}
# Check problem fields
MediaWiki::logger.warn "Field beschreibung in #{episode["url"]} empty" if episode["description"] == ""
# Get a real date
erste_sendung.gsub!(/\s*um\s*\d+:\d+$/,"")
if erste_sendung !~ /^[0-9]{2}\.[0-9]{2}\.[0-9]{4}.*$/
$stderr.puts "Field '#{erste_sendung}' in #{episode["url"]} looks funny, fall back to today."
MediaWiki::logger.warn "Field erste_sendung='#{erste_sendung}' in #{episode["url"]} looks funny, fall back to today."
else
episode["date"] = Date.parse(datum2isodate(erste_sendung))
end
@ -57,12 +75,16 @@ episodes = []
episode["length"] = head["content-length"]
episode["type"] = head["content-type"]
# More foo
episode["summary"] = episode["summary"] + ERB.new(TPL_SUMMARY_ADD).result(binding)
episode["content:encoded"] = to_html(episode["summary"])
# We just assume that the episode's length is an hour or so
episode["duration"] = "00:59:59"
episodes.push(episode)
end
# $stderr.puts "DEBUG: Only crawling one episode"; break
#MediaWiki::logger.warn "DEBUG: Only crawling one episode"; break
end
# Sort episodes, starting with last