egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
greenbear
Owner


Joined: 24 Sep 2001
Posts: 733
Location: Norway

PostPosted: Thu Jul 07, 2005 7:01 pm    Post subject: tv.com.tcl - parses tonights tv shows from tv.com Reply with quote

Show what's on tv tonight

Code:
############################################
# 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
Back to top
View user's profile Send private message Send e-mail
theauth0r
Voice


Joined: 04 Aug 2005
Posts: 6

PostPosted: Thu Aug 04, 2005 5:04 pm    Post subject: Reply with quote

Anyone got an updated version of this please.?
Back to top
View user's profile Send private message
greenbear
Owner


Joined: 24 Sep 2001
Posts: 733
Location: Norway

PostPosted: Thu Aug 04, 2005 10:21 pm    Post subject: Reply with quote

I updated the code posted above.

Remember to change 'tvoffset' so it matches your timezone.
It's needed to create the cookie.
Back to top
View user's profile Send private message Send e-mail
avilon
Halfop


Joined: 13 Jul 2004
Posts: 64
Location: Germany

PostPosted: Fri Aug 05, 2005 7:30 am    Post subject: Reply with quote

Code:
 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 [list]
Code:
set data [string map [list \n "" "</tr>" "</tr>\n" "</div>" "</div>\n" "</td>" "</td>~" "f-normal\">"  "f-normal\">~"] $data]

Instead of
Code:
if ![regexp -nocase {[0-9]:[0-9][0-9][am|pm]} $out] {
you should use
Code:
if ![string match -nocase {[0-9]:[0-9][0-9][ap]m} $out]
which is about 5 times faster.
Back to top
View user's profile Send private message
greenbear
Owner


Joined: 24 Sep 2001
Posts: 733
Location: Norway

PostPosted: Fri Aug 05, 2005 10:24 am    Post subject: Reply with quote

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 Shocked

Thanks for the tips on coding styles that I didn't ask for, though.
Back to top
View user's profile Send private message Send e-mail
koom
Voice


Joined: 30 Jul 2005
Posts: 22

PostPosted: Sun Aug 07, 2005 4:28 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
theauth0r
Voice


Joined: 04 Aug 2005
Posts: 6

PostPosted: Wed Aug 17, 2005 6:54 pm    Post subject: Reply with quote

Back to the original topic.....

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

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



Any fixes possible please ?

Smile
Back to top
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Wed Aug 17, 2005 7:02 pm    Post subject: Reply with quote

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

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

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



Any fixes possible please ?

Smile

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
Back to top
View user's profile Send private message Visit poster's website
trooper
Voice


Joined: 10 Oct 2005
Posts: 1

PostPosted: Mon Oct 10, 2005 3:43 am    Post subject: Reply with quote

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

Code:
[09:42] <<trooper>> !trooper! !tonight


Does not give me any output, but i dont see any errors either. Chanset' +tv.

Thanks
Back to top
View user's profile Send private message
Lumsk
Voice


Joined: 12 Dec 2006
Posts: 1
Location: Norway

PostPosted: Tue Dec 12, 2006 9:49 pm    Post subject: wish... Reply with quote

Hehe.. I wish there was a Norwegian version of this script Sad
Back to top
View user's profile Send private message
romeo5k
Halfop


Joined: 28 Jul 2006
Posts: 46

PostPosted: Sat Feb 10, 2007 12:08 am    Post subject: hmmm Reply with quote

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??
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Sat Feb 10, 2007 2:21 am    Post subject: Reply with quote

Post the results of:
Code:
.set errorInfo

... you may be better assisted.
_________________
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Back to top
View user's profile Send private message Visit poster's website
romeo5k
Halfop


Joined: 28 Jul 2006
Posts: 46

PostPosted: Sat Feb 10, 2007 10:20 pm    Post subject: Reply with quote

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:
setudef flag tv
set errorInfo
<---- and got nothing...
I also inserted it after here
Code:
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:
!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!!
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber