| View previous topic :: View next topic |
| Author |
Message |
greenbear Owner
Joined: 24 Sep 2001 Posts: 733 Location: Norway
|
Posted: Thu Jul 07, 2005 7:01 pm Post subject: tv.com.tcl - parses tonights tv shows from tv.com |
|
|
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 |
|
 |
theauth0r Voice
Joined: 04 Aug 2005 Posts: 6
|
Posted: Thu Aug 04, 2005 5:04 pm Post subject: |
|
|
| Anyone got an updated version of this please.? |
|
| Back to top |
|
 |
greenbear Owner
Joined: 24 Sep 2001 Posts: 733 Location: Norway
|
Posted: Thu Aug 04, 2005 10:21 pm Post subject: |
|
|
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 |
|
 |
avilon Halfop

Joined: 13 Jul 2004 Posts: 64 Location: Germany
|
Posted: Fri Aug 05, 2005 7:30 am Post subject: |
|
|
| 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 |
|
 |
greenbear Owner
Joined: 24 Sep 2001 Posts: 733 Location: Norway
|
Posted: Fri Aug 05, 2005 10:24 am Post subject: |
|
|
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
Thanks for the tips on coding styles that I didn't ask for, though. |
|
| Back to top |
|
 |
koom Voice
Joined: 30 Jul 2005 Posts: 22
|
Posted: Sun Aug 07, 2005 4:28 am Post subject: |
|
|
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 |
|
 |
theauth0r Voice
Joined: 04 Aug 2005 Posts: 6
|
Posted: Wed Aug 17, 2005 6:54 pm Post subject: |
|
|
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 ?
 |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Wed Aug 17, 2005 7:02 pm Post subject: |
|
|
| 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 ?
 |
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 |
|
 |
trooper Voice
Joined: 10 Oct 2005 Posts: 1
|
Posted: Mon Oct 10, 2005 3:43 am Post subject: |
|
|
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 |
|
 |
Lumsk Voice
Joined: 12 Dec 2006 Posts: 1 Location: Norway
|
Posted: Tue Dec 12, 2006 9:49 pm Post subject: wish... |
|
|
Hehe.. I wish there was a Norwegian version of this script  |
|
| Back to top |
|
 |
romeo5k Halfop
Joined: 28 Jul 2006 Posts: 46
|
Posted: Sat Feb 10, 2007 12:08 am Post subject: hmmm |
|
|
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 |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Sat Feb 10, 2007 2:21 am Post subject: |
|
|
Post the results of:
... you may be better assisted. _________________ Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM |
|
| Back to top |
|
 |
romeo5k Halfop
Joined: 28 Jul 2006 Posts: 46
|
Posted: Sat Feb 10, 2007 10:20 pm Post subject: |
|
|
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 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 |
|
 |
|