Hack 94. How Do You Watch TV?

   

Hack 94 How Do You Watch TV?

figs/expert.gif figs/hack94.gif

Compute your hunt-and-peck percentage to truly find out what kind of a viewer you are .

Are you a watch-the-show-all-the-way-through kind of TiVo user , or do you hunt and peck, watching 5 minutes of a show and moving on? Do you never finish watching what is on your Now Showing List ? Continuing our personal data mining, let's find out what kind of person you areat least according to your TiVo. We'll compute your hunt-and-peck percentagewhat percentage, on average, of a show you typically watchdown to the second. And with a little JavaScript magic, we'll share the outcome with the world on your web page.

The Code

 proc action_huntandpeck { chan path env } {            global db                                    # pull out the first 50 todo list shows from the database             set tododir "/Recording/NowShowingByTitle"         RetryTransaction {                  set files [mfs scan $tododir -count 50]        }                         set nshows 0                    set pshows 0                    while { [llength $files] > 0 } {                       # iterate through the shows we extracted           foreach rec $files {              set fsid [lindex $rec 0]                                      RetryTransaction {            # get the object that represents this recording.            # also figure out of the person has played this              # program then stopped -- if they did, the                                # bookmark will be set                  set recordingobj [db $db openid $fsid]                          set bookmark [dbobj $recordingobj get Bookmark]                 if { $bookmark != "" } {                       incr pshows           }                         incr nshows             }                          }                         # and grab the next 50 television shows            set lastName [lindex [lindex $files end] 1]                          RetryTransaction {                  set files [mfs scan $tododir -start $lastName -count 50]         }            if { $lastName == [lindex [lindex $files 0] 1] } {                      set files [lrange $files 1 end]               }         }            puts $chan "document.write( \"<span class=\"hptext\">My TiVo  [RETURN]  Hunt-and-Peck Ratio is</span> <span class=\"hpnum\">  [RETURN]  [expr ( $pshows * 1.0 ) / ( $nshows * 1.0 )]</span>\" );\                 }                         register_module "huntandpeck" "HuntAndPeck" "Are you a hunter or a pecker?" 

This hack is in the form of another TiVoWeb module [Hack #93]. Save this code as huntandpeck.itcl in the /var/hack/tivoweb-tcl/modules directory on your TiVo. Restart TiVoWeb by choosing Restart Full Reload from its menu bar. The module should be noticed and activated when TiVoWeb starts back up.

Running the Hack

Simply insert the following line into your HTML document where you'd like your hunt-and-peck percentage to appear:

 <script  language="JavaScript"  src="http://   my_tivo   /huntandpeck"> </script> 

Replace my_tivo with the hostname or IP address of your TiVo.

Upon encountering this tag, JavaScript-enabled web browsers (most modern browsers) will grab a fresh copy of your hunt-and-peck ratio from your TiVo, inserting it right into the page, like so:

 document.write( "<span class=\"hptext\">My TiVo Hunt-and-Peck Ratio  [RETURN]  is</span><span class=\"hpnum\"> 0.204081632653</span> " ); 

Apparently, I hunt and peck 20% of the time. Who'd have thunk it?

In actuality, you don't want to pull a fresh copy of your hun-and-peck ratio from your TiVo unit every time someone hits your web page. See the end of [Hack #93] for further discussion and solutions.


   
Top


Tivo Hacks. 100 Industrial-strength Tips Tools 2003
Tivo Hacks. 100 Industrial-strength Tips Tools 2003
ISBN: 1597490318
EAN: N/A
Year: 2004
Pages: 164

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net