#!/usr/bin/narf require 'booklib' require 'dbi' class Array def group_hash h=Hash.new self.each do |i| key=yield(i) unless(h[key]) h[key]=Array.new end h[key].push(i) end return h end end class BookEvent def to_html "#{author}: #{title} (#{store}, #{time.strftime("%l:%M %p")})
" end end DBI.connect('DBI:Pg:bookscraper','bookscraper',nil) do |dbh| events=BookEvent.import(dbh) dayhash=events.group_hash { |event| Date.jd(event.time.jd) } newhash=Hash.new dayhash.each_key do |key| newhash[key]=dayhash[key].sort{|a,b| a.time<=>b.time}.collect{|event| event.to_html}.join("\n") end newhash.each_key do |key| newhash[key]="

#{key.strftime("%B %e, %Y")}

"+newhash[key]+"
" end newtext='' newhash.keys.sort.each do |key| newtext+=newhash[key] end Web.content_type='text/html;charset=utf-8' Web.print_template("events-template.html", "text"=>newtext) end