1 proc rsstv_make_feed {title link description view {order asc}} { 2 dom createDocument rss doc 3 set rss [$doc documentElement] 4 $rss setAttribute version 2.0 5 $rss setAttribute xmlns:tv http://www.grumet.net/rsstv 6 set channel [$doc createElement channel] 7 $rss appendChild $channel 8 $channel appendChild [rsstv_simpleTextElement $doc title $title] 9 $channel appendChild [rsstv_simpleTextElement $doc link $link] 10 $channel appendChild [rsstv_simpleTextElement $doc description $description] 11 $channel appendChild [rsstv_simpleTextElement $doc pubDate [rsstv_rfc822date [ns_time]]] 12 $channel appendChild [rsstv_simpleTextElement $doc managingEditor aegrumet@alum.mit.edu] 13 14 db_foreach q " 15 select title, 16 sub_title, 17 description, 18 tvchannel, 19 to_char(when_start,'YYYYMMDDHH24MISS') as when_start, 20 to_char(when_stop,'YYYYMMDDHH24MISS') as when_stop, 21 to_char(case when when_order_by > current_timestamp then current_timestamp else when_order_by end,'Dy, DD Mon YYYY HH24:MI:SS') as pub_date, 22 to_char(extract(timezone_hour from current_timestamp),'FM09') as tzhour, 23 to_char(extract(timezone_minute from current_timestamp),'FM09') as tzminute 24 from rsstv_feed_$view 25 order by when_order_by $order 26 " { 27 append when_start " ${tzhour}${tzminute}" 28 append when_stop " ${tzhour}${tzminute}" 29 append pub_date " ${tzhour}${tzminute}" 30 set item [$doc createElement item] 31 $item appendChild [rsstv_simpleTextElement $doc title $title] 32 $item appendChild [rsstv_simpleTextElement $doc description $description] 33 $item appendChild [rsstv_simpleTextElement $doc pubDate $pub_date] 34 if { ![string equal $sub_title ""] } { 35 $item appendChild [rsstv_simpleTextElement $doc tv:sub-title $sub_title] 36 } 37 $item appendChild [rsstv_simpleTextElement $doc tv:tvchannel $tvchannel] 38 $item appendChild [rsstv_simpleTextElement $doc tv:start "$when_start"] 39 $item appendChild [rsstv_simpleTextElement $doc tv:stop "$when_stop"] 40 set guid [rsstv_simpleTextElement $doc guid "$tvchannel|$when_start"] 41 $guid setAttribute isPermaLink false 42 $item appendChild $guid 43 $channel appendChild $item 44 } 45 return [$doc asXML] 46 } 47 proc rsstv_rfc822date seconds { 48 return [ns_fmttime $seconds "%a, %d %b %Y %T %Z"] 49 } 50 proc rsstv_simpleTextElement {doc name value} { 51 set element_node [$doc createElement $name] 52 set value_node [$doc createTextNode $value] 53 $element_node appendChild $value_node 54 return $element_node 55 }