# # RssReader module for Tivo Control Station # version 0.1d -- Experimental # # by aegrumet@alum.mit.edu on 2004-01-28 # # Reads a RSS2.0 feed and displays it on your TV screen. # # This code is based loosely on the WebTemplate.tcl file # in tcs/modules/samples. # # You have to have a networked Tivo running Tivo Control Station # (http://www.zirakzigil.net/tivo/TCS.html) for this to work. # # Installation instructions # 1. Copy this file to your hard drive. # 2. Edit the IP Address, Host Name, and RSS path in GetFreshRss below. # 3. Stop TCS # 4. Copy the edited file to the TCS modules/modules subdirectory on Tivo. # 5. Create a link # cd tcs/modules # ln modules/RssReader.tcl # 6. /var/hack/tcs/starttcs & #Remove tags, unescape HTML entities, etc. proc RssCleanContent str { regsub -all {<} $str {<} str regsub -all {>} $str {>} str regsub -all {<[^>]*>} $str {} str regsub -all {"} $str {"} str return [string trim $str] } proc ProcessRssLine { s } { global WebFinished global RssStreamBuf global RssChanTitle global RssItems # EOF MAY never be set on the socket if {[eof $s] || [catch {gets $s line}]} { set WebFinished 1 catch {close $s} return } append RssStreamBuf $line #Try to get the channel title if we don't have it. if {[string compare $RssChanTitle ""] == 0 } { set StartTitle [string first "" $RssStreamBuf] set EndTitle [string first "" $RssStreamBuf] if { $EndTitle > -1 } { set TitleContent [string range $RssStreamBuf [expr $StartTitle + 7] [expr $EndTitle -1 ]] set RssChanTitle [RssCleanContent $TitleContent] #Discard everything up to and including set RssStreamBuf [string range $RssStreamBuf [expr $EndTitle + 8] end] } } set StartItem [string first "" $RssStreamBuf] set EndItem [string first "" $RssStreamBuf] if { $StartItem > -1 && [string compare $RssChanTitle ""] == 0 } { set RssChanTitle "Error parsing channel title" } while { $StartItem > -1 && $EndItem > -1 && $EndItem > $StartItem } { set ItemContent [string range $RssStreamBuf [expr $StartItem + 6] [expr $EndItem -1 ]] if { [regexp -nocase {(.*)} $ItemContent match ItemTitle] } { lappend RssItems [RssCleanContent $ItemTitle] } else { if { [regexp -nocase {(.*)} $ItemContent match ItemDesc] } { set CleanItemDesc [RssCleanContent $ItemDesc] if { [string length $CleanItemDesc] > 36 } { set CleanItemDesc "[string range $CleanItemDesc 0 35]..." } lappend RssItems $CleanItemDesc } } set RssStreamBuf [string range $RssStreamBuf [expr $EndItem + 6] end] set StartItem [string first "" $RssStreamBuf] set EndItem [string first "" $RssStreamBuf] } #Quit parsing as early as we can. if { [llength $RssItems] > 8 || [string first "" $line] > -1} { set WebFinished 1 } return } proc WriteRssReaderFile {path} { global RssStreamBuf global RssChanTitle global RssItems set f [open $path w 0777] if { [string length $RssChanTitle] > 40} { set RssChanTitle [string range $RssChanTitle 0 39] } puts $f "$RssChanTitle" puts $f [CurrentTime] puts $f "" foreach item $RssItems { puts $f "$item" puts $f "" } flush $f close $f return 1 } proc InitializeRssReader {} { global RssStreamBuf global RssChanTitle global RssItems set RssStreamBuf "" set RssChanTitle "" set RssItems [list] } proc GetFreshRss {} { InitializeRssReader GetWebPage RssReader "63.211.182.19" "www.scripting.com" "/rss.xml" ProcessRssLine global RssReaderFile set result [WriteRssReaderFile $RssReaderFile] dputs "RssReader Complete" dputs "" if {$result} { return 1 } else { puts "[CurrentTime] RssReader timeout" dputs "RssReader Complete" dputs "" return 0 } } proc InstallRssReaderModule {} { ###### GLOBALS global evrc global RssReaderFile ###### CONSTANTS # Set the directory where we are set directory [file dirname [file dirname [info script]]] # Output file with the RssReader data set RssReaderFile "$directory/displayfiles/RssReader.out" # How often to look up the RssReader data in minutes set updatefrequency 60 ###### INITIALIZE #after 30000 set remotecommand [list $evrc(6) $evrc(3) $evrc(clear)] set periodicupdatefrequency [expr $updatefrequency*60*1000] set periodicupdatecommand "GetFreshRss" set RssReaderDisplayStyle 0 set RssReaderClearScreenStyle 0 set updateisgreedy 1 InstallRemoteCommand "RssReader" \ $remotecommand \ $periodicupdatefrequency \ "DisplayFile $RssReaderFile" \ $periodicupdatecommand \ $RssReaderDisplayStyle \ $RssReaderClearScreenStyle \ $updateisgreedy } InstallRssReaderModule