2005-09-30 02:46:35 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								#!/usr/bin/env ruby
							 
						 
					
						
							
								
									
										
										
										
											2006-04-17 22:24:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								$:.unshift('vendor/ruby-mediawiki/lib')
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								require 'mediawiki/dotfile'
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 15:59:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								require 'cgi'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								require 'date'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								require 'erb'
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 17:48:30 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								require 'net/http'
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 18:08:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								require 'neinomat.lib.rb'
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 15:59:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#----------------------------------------------------------------------------
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# Constants
							 
						 
					
						
							
								
									
										
										
										
											2006-10-12 17:17:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								RFC822 = "%a, %d %b %Y %T %z" # for Date::strftime
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 18:03:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								require "#{$0}.templates.rb"
							 
						 
					
						
							
								
									
										
										
										
											2006-10-12 17:17:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#----------------------------------------------------------------------------
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 16:59:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# Some helper functions
							 
						 
					
						
							
								
									
										
										
										
											2006-10-12 17:17:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 17:48:30 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								def head(url)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  uri = URI.parse(url)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  Net::HTTP.start(uri.host, uri.port) do |http|
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    http.head(uri.path)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  end
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								end
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-12 17:17:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								#----------------------------------------------------------------------------
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 16:59:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# Get episodes from wiki
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								@wiki = MediaWiki.dotfile(nil,'entropia')
							 
						 
					
						
							
								
									
										
										
										
											2006-10-12 17:17:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-09-30 02:46:35 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								template = "Vorlage:Radio Chaotica-Sendung"
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 16:59:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								episodes = []
							 
						 
					
						
							
								
									
										
										
										
											2006-04-17 22:24:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								@wiki.article(template).what_links_here.each do |page|
							 
						 
					
						
							
								
									
										
										
										
											2006-10-12 17:17:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  # puts page # DEBUG
							 
						 
					
						
							
								
									
										
										
										
											2006-04-17 22:24:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  if erste_sendung = parse_template(page, template)["erste_sendung"]
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 16:59:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    episode = {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      "title"         => page,
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 17:56:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      "url"           => @wiki.full_article_url(page),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      "discussion"    => @wiki.full_article_url("Diskussion:#{page}"),
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 16:59:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      "enclosure_url" => parse_template(page, template)["download"],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      "date"          => Date.today(), # fallback
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-12 17:17:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    # Get a real date
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 16:59:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    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."
							 
						 
					
						
							
								
									
										
										
										
											2006-10-12 17:17:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    else
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 16:59:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      episode["date"] = Date.parse(datum2isodate(erste_sendung))
							 
						 
					
						
							
								
									
										
										
										
											2006-10-12 17:17:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    end
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 16:59:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    episode["pubdate"] = episode["date"].strftime(RFC822)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2006-10-12 17:17:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 17:48:30 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    # Get content type and length
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    head = head(episode["enclosure_url"])
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    episode["length"] = head["content-length"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    episode["type"]   = head["content-type"]
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 16:59:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 17:52:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    # We just assume that the episode's length is an hour or so
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 17:48:30 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    episode["duration"] = "00:59:59"
							 
						 
					
						
							
								
									
										
										
										
											2006-10-12 17:17:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 16:59:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    episodes.push(episode)
							 
						 
					
						
							
								
									
										
										
										
											2005-09-30 02:46:35 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								  end
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 17:48:30 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  $stderr.puts "DEBUG: Only crawling one episode"; break 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-12 17:17:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								end
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 18:03:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# Sort episodes, starting with last
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 16:59:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								episodes = episodes.sort do |x,y| 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-12 17:17:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  y["date"] <=> x["date"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								end
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#----------------------------------------------------------------------------
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 15:59:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# Generate RSS
							 
						 
					
						
							
								
									
										
										
										
											2006-10-12 17:17:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 15:59:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								items = ""
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 16:59:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								episodes.each do |episode|
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 15:59:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  items += ERB.new(TPL_ITEM).result(binding);
							 
						 
					
						
							
								
									
										
										
										
											2005-09-30 02:46:35 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								end
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-13 15:59:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								rss = ERB.new(TPL_RSS).result;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#puts rss #DEBUG
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								rssfile = File.new("/home/neingeist/public_html/chaotica.xml", "w")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								rssfile.puts rss
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								rssfile.close