neingeist
/
neinomaten
Archived
1
0
Fork 0

Make things a little nicer

master
neingeist 18 years ago
parent 3d1ba3b928
commit 1c982636c5

@ -5,8 +5,6 @@ require 'cgi'
require 'date'
require 'erb'
@wiki = MediaWiki.dotfile(nil,'entropia')
#----------------------------------------------------------------------------
# Constants
@ -63,29 +61,30 @@ ein podcast der sendungen des entropia e.v., chaos computer club karlsruhe auf q
'
TPL_ITEM = '
<item>
<title><%= CGI::escapeHTML(t["titel"]) %></title>
<link><%= t["url"] %></link>
<description><%= CGI::escapeHTML(t["titel"]) %></description>
<title><%= CGI::escapeHTML(episode["title"]) %></title>
<link><%= episode["url"] %></link>
<description><%= CGI::escapeHTML(episode["title"]) %></description>
<category>Talk Radio</category>
<enclosure url="<%= t["download"] %>" length="<%= t["length"] %>" type="audio/mpeg" />
<enclosure url="<%= episode["enclosure_url"] %>" length="<%= episode["length"] %>" type="audio/mpeg" />
<guid isPermaLink="true"><%= t["url"] %></guid>
<pubDate><%= t["pubdate"] %></pubDate>
<comments><%= t["discussion"] %></comments>
<content:encoded><%= CGI::escapeHTML(t["titel"]) %></content:encoded>
<guid isPermaLink="true"><%= episode["url"] %></guid>
<pubDate><%= episode["pubdate"] %></pubDate>
<comments><%= episode["discussion"] %></comments>
<content:encoded><%= CGI::escapeHTML(episode["title"]) %></content:encoded>
<author>radio@entropia.de</author>
<itunes:explicit xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">no</itunes:explicit>
<itunes:author xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">Entropia e.V. Karlsruhe</itunes:author>
<itunes:keywords xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">entropia,karlsruhe,ccc,hacking,computer,technology,society,chaosradio,chaos,politics</itunes:keywords>
<itunes:duration xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"><%= t["duration"] %></itunes:duration>
<itunes:subtitle xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"><%= CGI::escapeHTML(t["titel"]) %></itunes:subtitle>
<itunes:summary xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"><%= CGI::escapeHTML(t["titel"]) %></itunes:summary>
<itunes:duration xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"><%= episode["duration"] %></itunes:duration>
<itunes:subtitle xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"><%= CGI::escapeHTML(episode["title"]) %></itunes:subtitle>
<itunes:summary xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"><%= CGI::escapeHTML(episode["title"]) %></itunes:summary>
</item>
'
#----------------------------------------------------------------------------
# Some helper functions
def parse_template(title, template)
template_re = Regexp.new("\\\{\\\{" + template + "(.*?)\\\}\\\}")
@ -117,40 +116,45 @@ def datum2isodate(datum)
end
#----------------------------------------------------------------------------
sendungen = []
# Get episodes from wiki
@wiki = MediaWiki.dotfile(nil,'entropia')
template = "Vorlage:Radio Chaotica-Sendung"
episodes = []
@wiki.article(template).what_links_here.each do |page|
# puts page # DEBUG
if erste_sendung = parse_template(page, template)["erste_sendung"]
sendung = {}
sendung["datum"] = erste_sendung.gsub(/\s*um\s*\d+:\d+$/,"")
sendung["titel"] = page
sendung["url"] = "http://entropia.de/wiki/#{CGI::escape(page)}"
sendung["discussion"] = "http://entropia.de/wiki/Diskussion:#{CGI::escape(page)}"
sendung["download"] = parse_template(page, template)["download"]
episode = {
"title" => page,
"url" => "http://entropia.de/wiki/#{CGI::escape(page)}",
"discussion" => "http://entropia.de/wiki/Diskussion:#{CGI::escape(page)}",
"enclosure_url" => parse_template(page, template)["download"],
"date" => Date.today(), # fallback
}
# Get a real date
if sendung["datum"] !~ /^[0-9]{2}\.[0-9]{2}\.[0-9]{4}.*$/
$stderr.puts "#{sendung["datum"]} looks funny, fall back to today."
sendung["date"] = Date.today()
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."
else
sendung["date"] = Date.parse(datum2isodate(sendung["datum"]))
episode["date"] = Date.parse(datum2isodate(erste_sendung))
end
sendung["pubdate"] = sendung["date"].strftime(RFC822)
episode["pubdate"] = episode["date"].strftime(RFC822)
# FIXME
sendung["length"] = 57671680
sendung["duration"] = "00:59:59"
episode["length"] = 57671680
episode["duration"] = "00:59:59"
sendungen.push(sendung)
else
$stderr.puts page, ": erste_sendung nicht gesetzt"
episodes.push(episode)
end
# break # DEBUG
end
sendungen = sendungen.sort do |x,y|
episodes = episodes.sort do |x,y|
y["date"] <=> x["date"]
end
@ -158,7 +162,7 @@ end
# Generate RSS
items = ""
sendungen.each do |t|
episodes.each do |episode|
items += ERB.new(TPL_ITEM).result(binding);
end