#!/usr/bin/env ruby
#
# RDFWeb RSS Info harvester 
#
# Query RDFWeb aggregate for information about RSS channels.
# Generate HTML.
# Assumes data has been drafragmented / smushed.
#
# danbri $Id: rss_directory.rb,v 1.2 2002/07/07 00:19:16 danbri Exp $

require 'squish'
require '../../basicrdf'
require 'dbi'

query=<<EOQ;

	SELECT ?uri, ?title, ?desc,  
	WHERE (rdf::type ?uri rss::channel)
	(rss::title ?uri ?title)
	(rss::description ?uri ?desc)
	USING 
	rdf for http://www.w3.org/1999/02/22-rdf-syntax-ns#
	rss for http://purl.org/rss/1.0/
	foaf for http://xmlns.com/foaf/0.1/  
	dc for http://purl.org/dc/elements/1.1/
EOQ

DBI_DRIVER = 'DBI:Pg:test1'
DBI_USER = 'danbri'
DBI_PASS=''

q = SquishQuery.new.parseFromText query


puts '<?xml version="1.0" encoding="UTF-8"?>'
puts ''
puts '<html xmlns="http://www.w3.org/1999/xhtml">'


puts "<head><title>RDFWeb: RSS Channel Directory</title></head>\n\n<body>\n"
puts "<h1>RSS 1.0 Channels:</h1>\n\n"

puts "<ul>\n\n"

DBI.connect( DBI_DRIVER, DBI_USER, DBI_PASS) do | dbh |
  dbh.select_all( q.toSQLQuery  ) do | c |
    channel=ResultRow.new c

    channel.desc.gsub! ( /\\u(....)/ )  {|s| "\&#x#{$1};"  }  
    channel.title.gsub! ( /\\u(....)/ )  {|s| "\&#x#{$1};"  }  
    
    puts "<li><a href=\"#{channel.uri}\">#{channel.title}</a> <em>#{channel.desc}</em></li>";

  end
end

puts "</ul>"

puts "\n\n</body>\n</html>\n\n"
