gib mir rss schnell und dreckig
This commit is contained in:
		
							parent
							
								
									032ea932c4
								
							
						
					
					
						commit
						7b9072bfa1
					
				
					 1 changed files with 132 additions and 13 deletions
				
			
		| 
						 | 
				
			
			@ -3,6 +3,13 @@ $:.unshift('vendor/ruby-mediawiki/lib')
 | 
			
		|||
require 'mediawiki/dotfile'
 | 
			
		||||
@wiki = MediaWiki.dotfile(nil,'entropia')
 | 
			
		||||
 | 
			
		||||
require 'date'
 | 
			
		||||
require 'cgi'
 | 
			
		||||
 | 
			
		||||
RFC822 = "%a, %d %b %Y %T %z" # for Date::strftime
 | 
			
		||||
 | 
			
		||||
#----------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
def parse_template(title, template)
 | 
			
		||||
  template_re = Regexp.new("\\\{\\\{" + template + "(.*?)\\\}\\\}")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -18,7 +25,7 @@ def parse_template(title, template)
 | 
			
		|||
      (key, value) = field.split(/=/)
 | 
			
		||||
      fields[key] = value
 | 
			
		||||
      field = ""
 | 
			
		||||
    else 
 | 
			
		||||
    else
 | 
			
		||||
      inlink += 1 if c == "["
 | 
			
		||||
      inlink -= 1 if c == "]"
 | 
			
		||||
      field += c
 | 
			
		||||
| 
						 | 
				
			
			@ -28,17 +35,129 @@ def parse_template(title, template)
 | 
			
		|||
  fields
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
body = ""
 | 
			
		||||
template = "Vorlage:Radio Chaotica-Sendung"
 | 
			
		||||
@wiki.article(template).what_links_here.each do |page|
 | 
			
		||||
  if erste_sendung = parse_template(page, template)["erste_sendung"]
 | 
			
		||||
    datum = erste_sendung.gsub(/\s*um\s*\d+:\d+$/,"")
 | 
			
		||||
    body += "* " + datum + " [[" + page + "]]\n"
 | 
			
		||||
  else
 | 
			
		||||
    $stderr.print(page, ": erste_sendung nicht gesetzt")
 | 
			
		||||
  end
 | 
			
		||||
def datum2isodate(datum)
 | 
			
		||||
  return datum[6..9] + "-" + datum[3..4] + "-" + datum[0..1]
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
a = @wiki.article("Benutzer:Neingeist/Radio Chaotica-Liste")
 | 
			
		||||
a.text = body
 | 
			
		||||
a.submit("Radio Chaotica-Liste")
 | 
			
		||||
#----------------------------------------------------------------------------
 | 
			
		||||
sendungen = []
 | 
			
		||||
 | 
			
		||||
template = "Vorlage:Radio Chaotica-Sendung"
 | 
			
		||||
@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/Diksussion#{CGI::escape(page)}"
 | 
			
		||||
    sendung["download"]     = parse_template(page, template)["download"]
 | 
			
		||||
 
 | 
			
		||||
    # 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()
 | 
			
		||||
    else
 | 
			
		||||
      sendung["date"] = Date.parse(datum2isodate(sendung["datum"]))
 | 
			
		||||
    end
 | 
			
		||||
    sendung["pubdate"] = sendung["date"].strftime(RFC822)
 | 
			
		||||
 
 | 
			
		||||
    # FIXME
 | 
			
		||||
    sendung["length"]   = 57671680
 | 
			
		||||
    sendung["duration"] = "00:59:59"
 | 
			
		||||
 | 
			
		||||
    sendungen.push(sendung)
 | 
			
		||||
  else
 | 
			
		||||
    $stderr.puts page, ": erste_sendung nicht gesetzt"
 | 
			
		||||
  end
 | 
			
		||||
  # break # DEBUG
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
sendungen = sendungen.sort do |x,y| 
 | 
			
		||||
  y["date"] <=> x["date"]
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
#----------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
body = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
 | 
			
		||||
<rss version=\"2.0\" 
 | 
			
		||||
  xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
 | 
			
		||||
  xmlns:sy=\"http://purl.org/rss/1.0/modules/syndication/\"
 | 
			
		||||
  xmlns:admin=\"http://webns.net/mvcb/\"
 | 
			
		||||
  xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
 | 
			
		||||
  xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">
 | 
			
		||||
 | 
			
		||||
<channel>
 | 
			
		||||
<title>radio chaotica podcast</title>
 | 
			
		||||
<link>http://entropia.de/wiki/Radio%20Chaotica</link>
 | 
			
		||||
<description>ein podcast der sendungen des entropia e.v., chaos computer club karlsruhe auf querfunk, 104.8 mhz</description>
 | 
			
		||||
<category>Talk Radio</category>
 | 
			
		||||
<generator>MediaWiki neinomat</generator>
 | 
			
		||||
<language>de</language>
 | 
			
		||||
<copyright>Entropia e.V. Karlsruhe</copyright>
 | 
			
		||||
 | 
			
		||||
<managingEditor>radio@entropia.de (Radio Chaotica)</managingEditor>
 | 
			
		||||
<pubDate>#{Time.now.strftime(RFC822)}</pubDate>
 | 
			
		||||
<image>
 | 
			
		||||
  <url>http://podcast.entropia.de/chaotica-100x300-crappy.png</url>
 | 
			
		||||
  <width>100</width>
 | 
			
		||||
  <height>300</height>
 | 
			
		||||
  <link>http://entropia.de/wiki/Radio%20Chaotica</link>
 | 
			
		||||
  <title>Radio Chaotica</title>
 | 
			
		||||
</image>
 | 
			
		||||
 | 
			
		||||
<sy:updatePeriod>daily</sy:updatePeriod>
 | 
			
		||||
<sy:updateFrequency>1</sy:updateFrequency>
 | 
			
		||||
<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
 | 
			
		||||
 | 
			
		||||
<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\">
 | 
			
		||||
ein podcast der sendungen des entropia e.v., chaos computer club karlsruhe auf querfunk, 104.8 mhz
 | 
			
		||||
</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:category xmlns:itunes=\"http://www.itunes.com/dtds/podcast-1.0.dtd\" text=\"News & Politics\"/>
 | 
			
		||||
<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: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:owner xmlns:itunes=\"http://www.itunes.com/dtds/podcast-1.0.dtd\">
 | 
			
		||||
  <itunes:name>Entropia e.V. Karlsruhe</itunes:name>
 | 
			
		||||
  <itunes:email>radio@entropia.de</itunes:email>
 | 
			
		||||
</itunes:owner>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
"
 | 
			
		||||
 | 
			
		||||
sendungen.each do |t|
 | 
			
		||||
  body += "
 | 
			
		||||
<item>
 | 
			
		||||
  <title>#{CGI::escapeHTML(t["titel"])}</title> 
 | 
			
		||||
  <link>#{t["url"]}</link>
 | 
			
		||||
  <description>#{CGI::escapeHTML(t["titel"])}</description>
 | 
			
		||||
  <category>Talk Radio</category>
 | 
			
		||||
  <enclosure url=\"#{t["download"]}\" length=\"#{t["length"]}\" type=\"audio/mpeg\" />
 | 
			
		||||
 | 
			
		||||
  <guid isPermaLink=\"false\">#{t["url"]}</guid>
 | 
			
		||||
  <pubDate>#{t["pubdate"]}</pubDate>
 | 
			
		||||
  <comments>#{t["discussion"]}</comments>
 | 
			
		||||
  <content:encoded>#{CGI::escapeHTML(t["titel"])}</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>
 | 
			
		||||
 | 
			
		||||
</item>
 | 
			
		||||
"
 | 
			
		||||
end
 | 
			
		||||
body += "</channel></rss>"
 | 
			
		||||
 | 
			
		||||
#puts body #DEBUG
 | 
			
		||||
rss = File.new("/home/neingeist/public_html/chaotica.xml", "w")
 | 
			
		||||
rss.puts body
 | 
			
		||||
rss.close
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue