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