tv.com.tcl - parses tonights tv shows from tv.com

Support & discussion of released scripts, and announcements of new releases.
Post Reply
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

tv.com.tcl - parses tonights tv shows from tv.com

Post by greenbear »

Show what's on tv tonight

Code: Select all

############################################
# tv.com.tcl v0.2 by greenbear at gmail.com
#
# Parses tonights tv shows from tv.com
#
# Enable with .chanset #channel +tv
#

# offset to EST
# 6 hours makes sense for CET (Europe)
set tvoffset 6

bind pub - !tonight pub:tv.com

if ![info exists egghttp(version)] {
  putlog "egghttp.tcl was NOT successfully loaded."
}

setudef flag tv

proc pub:tv.com {nick uhost hand chan text} {
  if ![channel get $chan tv] return
  set d [strftime %m%d%y]
  set d [date:offset [clock seconds] %m%d%y]
  set sock [egghttp:geturl http://www.tv.com/ [list parse:tv.com $chan] -headers "Cookie: tv_promo_$d=1"]
}

proc parse:tv.com {chan sock} {
 set data [egghttp:data $sock]
 egghttp:cleanup $sock

 set data [string map {"\n" ""} $data]
 set data [string map {"</tr>" "</tr>\n"} $data]
 set data [string map {"</div>" "</div>\n"} $data]
 set data [string map {"</td>" "</td>~"} $data]
 set data [string map {"f-normal\">" "f-normal\">~"} $data]

 set parse 0
 foreach line [split $data \n] {
  if [string match -noc "*<h3>What's On Tonight</h3>*" $line] {set parse 1}
  if {$parse&&[string match -noc *</table>* $line]} {return}
  if {$parse} {
    regsub -all {<(.|\n)*?>} $line {} clean
    set out [join $clean]
    if {$out!=""&&$out!="~"&&![string match -noc "*What's On Tonight*" $out]} {
      set ts [concat [lindex [split $out ~] 0]]
      set ch [concat [lindex [split $out ~] 3]]
      set sh [concat [lindex [split $out ~] 1]]
      set ep [concat [lindex [split $out ~] 2]]
      if ![regexp -nocase {[0-9]:[0-9][0-9][am|pm]} $out] {
        putserv "PRIVMSG $chan :$sh \002\[\002\00304$ep\017\002\]\002 ($ch)"
      } {
        putserv "PRIVMSG $chan :$sh \002\[\002\00304$ep\017\002\]\002 ($ch at $ts)"
      }
    }
  }
 }
}

proc date:offset {epox arg} {
 set t [expr $epox-((60*60)*$::tvoffset)]
 set w [clock format $t -format $arg]
 return $w
}

putlog "* tv.com.tcl loaded."
Updated to work with tv.com's new cookies
Last edited by greenbear on Thu Aug 04, 2005 10:19 pm, edited 1 time in total.
t
theauth0r
Voice
Posts: 6
Joined: Thu Aug 04, 2005 5:01 pm

Post by theauth0r »

Anyone got an updated version of this please.?
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

I updated the code posted above.

Remember to change 'tvoffset' so it matches your timezone.
It's needed to create the cookie.
User avatar
avilon
Halfop
Posts: 64
Joined: Tue Jul 13, 2004 6:58 am
Location: Germany

Post by avilon »

Code: Select all

 set data [string map {"\n" ""} $data]
 set data [string map {"</tr>" "</tr>\n"} $data]
 set data [string map {"</div>" "</div>\n"} $data]
 set data [string map {"</td>" "</td>~"} $data]
 set data [string map {"f-normal\">" "f-normal\">~"} $data]
You could merge them in a single "string map" using
  • Code: Select all

    set data [string map [list \n "" "</tr>" "</tr>\n" "</div>" "</div>\n" "</td>" "</td>~" "f-normal\">"  "f-normal\">~"] $data]
    Instead of

    Code: Select all

    if ![regexp -nocase {[0-9]:[0-9][0-9][am|pm]} $out] {
    you should use

    Code: Select all

    if ![string match -nocase {[0-9]:[0-9][0-9][ap]m} $out]
    which is about 5 times faster.
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

I'm no big fan of long lines, so I like to split stuff up so it's easier to read.
[list ...] and {...} is the same thing, btw.

I really should stop using regexp for everything, though... old habits die hard :shock:

Thanks for the tips on coding styles that I didn't ask for, though.
k
koom
Voice
Posts: 22
Joined: Sat Jul 30, 2005 9:23 pm

Post by koom »

hi there greenbear,

a bit off topic from this, but would you be able to make a script that parses tv show information from tv.com?

Example here:
http://forum.egghelp.org/viewtopic.php?t=10211

I understand if you dont really feel like making this script, but hopefully you can nudge me in the right direction (keeping in mind that i am a noob at tcl..)

Thanks alot,
koom
t
theauth0r
Voice
Posts: 6
Joined: Thu Aug 04, 2005 5:01 pm

Post by theauth0r »

Back to the original topic.....

im getting an error all of a sudden when i do !imdb

Code: Select all

Tcl error [imdb_proc]: can't read "location": no such variable

Any fixes possible please ?

:)
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

theauth0r wrote:Back to the original topic.....

im getting an error all of a sudden when i do !imdb

Code: Select all

Tcl error [imdb_proc]: can't read "location": no such variable

Any fixes possible please ?

:)
I'd suggest you READ this threads subject. It has nothing whatever to do with imbd.tcl. Contact the author.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
t
trooper
Voice
Posts: 1
Joined: Mon Oct 10, 2005 3:33 am

Post by trooper »

Any requirements beyond egghttp.tcl and tv.com.tcl ? egg version? newer cookies?

Code: Select all

[09:42] <<trooper>> !trooper! !tonight 
Does not give me any output, but i dont see any errors either. Chanset' +tv.

Thanks
L
Lumsk
Voice
Posts: 1
Joined: Tue Dec 12, 2006 9:22 pm
Location: Norway

wish...

Post by Lumsk »

Hehe.. I wish there was a Norwegian version of this script :(
r
romeo5k
Halfop
Posts: 46
Joined: Fri Jul 28, 2006 9:02 am

hmmm

Post by romeo5k »

i loaded , and it shows in partyline that everything was loaded.. Now i go to the channel and type !tonight and i get no error. but i dont get the shows either. this is what i did so far.
I copied the script above and pasted and made it a tcl.
then i inserted the egghttp in the scripts
i changed the offset thing to -6
and i wentinto partyline and typed .chanset #testing +tv
So with all that said, where did i mess up on??
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Post the results of:

Code: Select all

.set errorInfo
... you may be better assisted.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
r
romeo5k
Halfop
Posts: 46
Joined: Fri Jul 28, 2006 9:02 am

Post by romeo5k »

sorry to sound stoopid Alchera, but where in the script do u want me to insert that.. This way i dont get an error for insetrting it in the wrong place... Sorry for a noob question if it is.!
********************
edit**
i inserted it after here

Code: Select all

setudef flag tv
set errorInfo 
<---- and got nothing...
I also inserted it after here

Code: Select all

set data [string map {"\n" ""} $data]
 set data [string map {"</tr>" "</tr>\n"} $data]
 set data [string map {"</div>" "</div>\n"} $data]
 set data [string map {"</td>" "</td>~"} $data]
 set data [string map {"f-normal\">" "f-normal\">~"} $data] 
 set errorInfo
<---- and still got nothing..
I still get no errors.. no nothing..
Lemme ask a stoopid question..: The trigger is set to

Code: Select all

!tonight
by default, correct? At least thats what ive been useing..
Also.. i DID NOT use the editing code that avilon posted.. im using the complete default thats on the first post.!
Sorry for the stoopid questions but im in between beginer and intermediate!!
Post Reply