neingeist
/
neinomaten
Archived
1
0
Fork 0

Better feed now

master
neingeist 18 years ago
parent f5b07db285
commit d0ffc55b65

@ -16,6 +16,7 @@ require "#{$0}.templates.rb"
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# Some helper functions # Some helper functions
# Get HEAD info from an URL
def head(url) def head(url)
uri = URI.parse(url) uri = URI.parse(url)
@ -24,6 +25,16 @@ def head(url)
end end
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 # Get episodes from wiki
@ -34,19 +45,26 @@ 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"] episode_info = parse_template(page, template)
if erste_sendung = episode_info["erste_sendung"]
episode = { episode = {
"title" => page, "title" => page,
"url" => @wiki.full_article_url(page), "url" => @wiki.full_article_url(page),
"discussion" => @wiki.full_article_url("Diskussion:#{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 "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 # Get a real date
erste_sendung.gsub!(/\s*um\s*\d+:\d+$/,"") erste_sendung.gsub!(/\s*um\s*\d+:\d+$/,"")
if erste_sendung !~ /^[0-9]{2}\.[0-9]{2}\.[0-9]{4}.*$/ 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 else
episode["date"] = Date.parse(datum2isodate(erste_sendung)) episode["date"] = Date.parse(datum2isodate(erste_sendung))
end end
@ -57,12 +75,16 @@ episodes = []
episode["length"] = head["content-length"] episode["length"] = head["content-length"]
episode["type"] = head["content-type"] 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 # We just assume that the episode's length is an hour or so
episode["duration"] = "00:59:59" episode["duration"] = "00:59:59"
episodes.push(episode) episodes.push(episode)
end end
# $stderr.puts "DEBUG: Only crawling one episode"; break #MediaWiki::logger.warn "DEBUG: Only crawling one episode"; break
end end
# Sort episodes, starting with last # Sort episodes, starting with last

@ -32,6 +32,9 @@ TPL_RSS = '<?xml version="1.0" encoding="utf-8"?>
<itunes:subtitle xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">ein podcast der sendungen des entropia e.v., chaos computer club karlsruhe auf querfunk, 104.8 mhz</itunes:subtitle> <itunes:subtitle xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">ein podcast der sendungen des entropia e.v., chaos computer club karlsruhe auf querfunk, 104.8 mhz</itunes:subtitle>
<itunes:summary xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"> <itunes:summary xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
ein podcast der sendungen des entropia e.v., chaos computer club karlsruhe auf querfunk, 104.8 mhz ein podcast der sendungen des entropia e.v., chaos computer club karlsruhe auf querfunk, 104.8 mhz
infos zur sendung unter:
http://entropia.de/wiki/Radio_Chaotica
</itunes:summary> </itunes:summary>
<itunes:image xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" href="http://podcast.entropia.de/chaotica-300x300-crappy.png"/> <itunes:image xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" href="http://podcast.entropia.de/chaotica-300x300-crappy.png"/>
@ -52,14 +55,14 @@ TPL_ITEM = '
<item> <item>
<title><%= CGI::escapeHTML(episode["title"]) %></title> <title><%= CGI::escapeHTML(episode["title"]) %></title>
<link><%= episode["url"] %></link> <link><%= episode["url"] %></link>
<description><%= CGI::escapeHTML(episode["title"]) %></description> <description><%= CGI::escapeHTML(episode["description"]) %></description>
<category>Talk Radio</category> <category>Talk Radio</category>
<enclosure url="<%= episode["enclosure_url"] %>" length="<%= episode["length"] %>" type="<%= episode["type"] %>" /> <enclosure url="<%= episode["enclosure_url"] %>" length="<%= episode["length"] %>" type="<%= episode["type"] %>" />
<guid isPermaLink="true"><%= episode["url"] %></guid> <guid isPermaLink="true"><%= episode["url"] %></guid>
<pubDate><%= episode["pubdate"] %></pubDate> <pubDate><%= episode["pubdate"] %></pubDate>
<comments><%= episode["discussion"] %></comments> <comments><%= episode["discussion"] %></comments>
<content:encoded><%= CGI::escapeHTML(episode["title"]) %></content:encoded> <content:encoded><%= CGI::escapeHTML(episode["content:encoded"]) %></content:encoded>
<author>radio@entropia.de</author> <author>radio@entropia.de</author>
@ -67,7 +70,19 @@ TPL_ITEM = '
<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"><%= episode["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(episode["title"]) %></itunes:subtitle> <itunes:subtitle xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<itunes:summary xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"><%= CGI::escapeHTML(episode["title"]) %></itunes:summary> <%= CGI::escapeHTML(episode["description"]) %>
</itunes:subtitle>
<itunes:summary xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"><%= CGI::escapeHTML(episode["summary"]) %></itunes:summary>
</item> </item>
' '
TPL_SUMMARY_ADD = '
Weitere Informationen zur Sendung gibt es unter:
<%= episode["url"] %>
Ihr habt Fragen und Anregungen? Hinterlasst sie uns auf der Diskussionsseite zur Sendung oder per Mail an radio@entropia.de:
<%= episode["discussion"] %>
Weitere Sendungen findet ihr hier: Radio Chaotica. Wir senden (fast ;-) jeden 3. Montag im Monat um 16:00 Uhr live auf Querfunk 104,8 MHz im Raum Karlsruhe. Für alle, die Querfunk nicht über UKW empfangen können, existiert auch der Querfunk Live-Stream (http://www.querfunk.de/live.html) oder natürlich unser Podcast - den ihr gerade lest oder hört :-)
'

@ -1,5 +1,5 @@
def parse_template(title, template) def parse_template(title, template)
template_re = Regexp.new("\\\{\\\{" + template + "(.*?)\\\}\\\}") template_re = Regexp.new("\\\{\\\{" + template + "(.*?)\\\}\\\}", Regexp::MULTILINE)
fields = {} fields = {}