This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

TVRage.com Schedule Script (Latest: 2.0)

Support & discussion of released scripts, and announcements of new releases.
Post Reply
T
Tammik
Voice
Posts: 10
Joined: Mon Jan 23, 2006 9:41 am

can't find package ncgi

Post by Tammik »

can't find package ncgi how do get that to work iam not so good at this..
G
GaveUp
Op
Posts: 139
Joined: Thu Jan 19, 2006 3:56 am

Post by GaveUp »

Google is your friend. It is part of tcllib. Install that and you'll have it.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

no need of ncgi if the input is supposed to contain only alnums (letters/digits) and spaces, simply [string map] space with +
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
G
GaveUp
Op
Posts: 139
Joined: Thu Jan 19, 2006 3:56 am

Post by GaveUp »

There's no guarantee of that. For example, you might search for "That 70's Show."
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

then encode non-alnums to their %XX representation:

Code: Select all

% set str "That 70's Show"
That 70's Show
% set str [string map {" " +} $str]
That+70's+Show
% foreach c [split $str {}] {
   if {$c == "+" || [string is alnum $c]} {append x $c} {
      binary scan $c H2 c; append x %$c
   }
}
% set x
That+70%27s+Show
% ncgi::encode "That 70's Show"
That+70%27s+Show
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

or use regexp for compactness:

Code: Select all

foreach c [split $str {}] {
   if [regexp {[+\w]} $c] {append x $c} {
      binary scan $c H2 c; append x %$c
   }
} 
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
b
bras
Voice
Posts: 7
Joined: Fri Feb 03, 2006 8:38 am

Post by bras »

Hi, thank you very much for this tcl. It's really god, however I will stick with version 0.2 because of the ncgi issue for me.
Anyway, what is !schedule for ? Type it and nothing seens to happen.

Thanks!
G
GaveUp
Op
Posts: 139
Joined: Thu Jan 19, 2006 3:56 am

Post by GaveUp »

Latest version removes ncgi requirement and further tweaks regexp's.

Code: Select all

####################
#    tvrage.tcl    #
#   v0.4 03Feb06   #
# Coded By: GaveUp #
####################

###################
#   DESCRIPTION   #
#################################################################################
# This script pulls today's or tomorrow's schedule of new shows from tvrage.com #
# Triggers:			                        											   #
#		!today -- Display today's schedule												   #
#     !tomorrow -- Display tomorrow's schedule											 #
#     !showinfo <show name> -- Display detailed information for <show name>     #
#     !schedule <day> -- Display schedule for <day>                             #
#                        <day> can be one of: mon, tue, wed, thu, fri, sat, sun #
#################################################################################

####################
# Revision History #
#####################################################################
# 0.4 -- *more tweaks to regex                                      #
#        *removed ncgi requirement                                  #
# 0.3 -- *fixed last time of 7th day now displayed                  #
#        *tweaked regex to catch some programs it was missing       # 
# 0.2 -- +!showinfo trigger for detailed show info and next/last ep #
#        +!schedule for 7 day schedule                              #
#        *fixed errors in various regex                             #
# 0.1 -- Initial Release                                            #
#                                                                   #
# + added   - removed   * fixed/changed                             #
#####################################################################

########
# TODO #
#################################################
# *Move hardcoded settings to variables.        #
# *Add support for changing timezones.          #
#################################################

### Begin Config ###

set tvrage(scheduleurl) "http://www.tvrage.com/quickschedule.php"
set tvrage(showinfourl) "http://www.tvrage.com/quickinfo.php"
set tvrage(scheduleTitle) "\00303New TV Shows for %%date%% ***All Times in EST/EDT***\00315"
set tvrage(c1) ""
set tvrage(c2) ""
set tvrage(c3) ""
set tvrage(c4) ""

### End Config ###

bind pub - !today pub:tvrage.com.today
bind pub - !tomorrow pub:tvrage.com.tomorrow
bind pub - !showinfo pub:tvrage.com.showinfo
bind pub - !schedule pub:tvrage.com.schedule

package require http
#package require ncgi
setudef flag tv

proc pub:tvrage.com.schedule {nick uhost hand chan text} {
	set seconds [clock seconds]
	set days(sun) 0
	set days(mon) 1
	set days(tue) 2
	set days(wed) 3
	set days(thu) 4
	set days(fri) 5
	set days(sat) 6

	if ![info exist days([string tolower $text])] return 

	set currDay [clock format $seconds -format "%w"]
	
	if {$currDay > $days([string tolower $text])} {
		parse:tvrage.com $nick $uhost $hand $chan $text [expr (7 - $currDay) + $days([string tolower $text])]
	} else {
		parse:tvrage.com $nick $uhost $hand $chan $text [expr $days([string tolower $text]) - $currDay]
	}
}
		

proc pub:tvrage.com.today {nick uhost hand chan text} {
	parse:tvrage.com $nick $uhost $hand $chan $text "0"
}

proc pub:tvrage.com.tomorrow {nick uhost hand chan text} {
	parse:tvrage.com $nick $uhost $hand $chan $text "1"
}

proc parse:tvrage.com.encodeURL {str} {
	set str [string map {" " +} $str] 
	foreach c [split $str {}] {
	   if {$c == "+" || [string is alnum $c]} {append x $c} {
	      binary scan $c H2 c; append x %$c
	   }
	} 

	return $x
}

proc pub:tvrage.com.showinfo {nick uhost hand chan text} {
	if ![channel get $chan tv] return
	
	#set token [http::geturl [join [list "http://www.tvrage.com/quickinfo.php?show=" [ncgi::encode [string trimleft $text]]] ""]]
	set token [http::geturl [join [list "http://www.tvrage.com/quickinfo.php?show=" [parse:tvrage.com.encodeURL [string trimleft $text]]] ""]]
	set data [http::data $token]
	http::cleanup $token
	set show(title) ""
	
	foreach line [split $data \n] {
		if {[regexp {^No Show Results Were Found For \".*\"$} $line]} {
			putserv "PRIVMSG $chan :\00303$line\00315"
			return
		}
		if {[regexp {^Show Name@(.*)$} $line -> match]} { set show(title) $match }
		if {[regexp {^Show URL@(.*)$} $line -> match]} { set show(url) $match }
		if {[regexp {^Premiered@(.*)$} $line -> match]} { set show(premiered) $match }
		if {[regexp {^Latest Episode@(\d+)x(\d+)\^([\w\'\.\, \#\&\@\:]+)\^([\w\/]+)$} $line -> season episode eptitle epDate]} { 
			set show(latest) [join [list "\00303Latest Episode ::\00315 \00304$season" "x$episode - $eptitle ($epDate)\00315"] ""]
		}
		if {[regexp {^Next Episode@(\d+)x(\d+)\^([\w\'\.\, \#\@\&\:]+)\^([\w\/]+)$} $line -> season episode eptitle epDate]} { 
			set show(next) [join [list "\00303Next Episode ::\00315 \00304$season" "x$episode - $eptitle ($epDate)\00315"] ""]
		}
		if {[regexp {^Country@(.*)$} $line -> match]} { set show(country) $match }
		if {[regexp {^Status@(.*)$} $line -> match]} { set show(status) $match }
		if {[regexp {^Classification@(.*)$} $line -> match]} { set show(class) $match }
	}

	if ![info exist show(next)] { set show(next) "\00303Next Episode ::\00315 \00304N/A\00315" }

	putserv "PRIVMSG $chan :\00303Title ::\00315 \00304$show(title)\00315 \00308<>\00315 \00303URL ::\00315 \00304$show(url)\00315 \00308<>\00315 \00303Premiered ::\00315 \00304$show(premiered)\00315 \00308<>\00315 $show(latest) \00308<>\00315 $show(next) \00308<>\00315 \00303Country ::\00315 \00304$show(country)\00315 \00308<>\00315 \00303Status ::\00315 \00304$show(status)\00315"
}
		
proc parse:tvrage.com {nick uhost hand chan text when} {
	if ![channel get $chan tv] return
	set token [http::geturl http://www.tvrage.com/quickschedule.php]
	set data [http::data $token]
	http::cleanup $token
	set date ""
	set systemTime [clock seconds]
	set systemTime [expr $systemTime + 3600]
	set currentTime ""
	set parsing 0
	set currentOutput ""
	set gotTime 0
	set neededDate ""
	set neof 1

	set systemTime [expr "$systemTime + ($when * 86400)"]
	set neededDate [clock format $systemTime -format "%A, %d %b %Y"]

	foreach line [split $data \n] {
		if {[regexp {^\[DAY\]([\w\, ]+)\[\/DAY\]$} $line -> date]} {
			if {$parsing == 1} {
				break;
			}
			
			if {$date == $neededDate} {
				putserv "PRIVMSG $chan :\00303New TV Shows for $date ***All Times in EST/EDT***\00315"
				set parsing 1
			}
		}

		if {$parsing} {
			if {[regexp {^\[TIME\]([\w\: ]+)\[\/TIME\]$} $line -> currentTime]} {
				if {$gotTime} {
					set currentOutput [string trim $currentOutput <>]
					putserv "PRIVMSG $chan :$currentOutput"
					set currentOutput ""
				}
			
				set currentOutput "\002$currentTime:\002 "
				set gotTime 1
			}

			regsub -all {\x92} $line {'} line
			#if !{[regexp {^\[SHOW\]([ \w\&\!]+)\^([\(\)\-\#\w \'\`\:&\!\/]+)\^([\dx]+)\^([\w\\\/\:\.\-]+)\[\/SHOW\]$} $line -> network title epnum url]} { putlog $line }
			if {[regexp {^\[SHOW\]([ \w\&\!]+)\^([\-\(\)\#\w \'\`\:&\!\/]+)\^([\dx]+)\^([\w\\\/\:\.\-]+)\[\/SHOW\]$} $line -> network title epnum url]} {
				set currentOutput [concat $currentOutput "\00304$network\00315 - \00314$title $epnum\00315 <>"]
			}
		}
	}

	if {$currentOutput != ""} {
		set currentOutput [string trim $currentOutput <>]
		putserv "PRIVMSG $chan :$currentOutput"
	}
}

putlog "TVRage.com Primetime Schedule v0.4"
T
Tammik
Voice
Posts: 10
Joined: Mon Jan 23, 2006 9:41 am

Post by Tammik »

if i type !showinfo Arrested Development
the script wount work..

getting this error..

Tcl error [pub:tvrage.com.showinfo]: can't read "show(latest)": no such
lement in array
G
GaveUp
Op
Posts: 139
Joined: Thu Jan 19, 2006 3:56 am

Post by GaveUp »

Are you using the latest version?
T
Tammik
Voice
Posts: 10
Joined: Mon Jan 23, 2006 9:41 am

Post by Tammik »

latest version of your script yes
G
GaveUp
Op
Posts: 139
Joined: Thu Jan 19, 2006 3:56 am

Post by GaveUp »

Was working here, but I had forgot I had made a few changes to the latest version. Here is the fixed script.

Code: Select all

####################
#    tvrage.tcl    #
#   v0.5 10Feb06   #
# Coded By: GaveUp #
####################

###################
#   DESCRIPTION   #
#################################################################################
# This script pulls today's or tomorrow's schedule of new shows from tvrage.com #
# Triggers:	                                                                    #
#		!today -- Display today's schedule										           #
#     !tomorrow -- Display tomorrow's schedule									        #
#     !showinfo <show name> -- Display detailed information for <show name>     #
#     !schedule <day> -- Display schedule for <day>                             #
#                        <day> can be one of: mon, tue, wed, thu, fri, sat, sun #
#################################################################################

####################
# Revision History #
#####################################################################
# 0.5 -- *Yet more regex tweaks                                     #
# 0.4 -- *more tweaks to regex                                      #
#        *removed ncgi requirement                                  #
# 0.3 -- *fixed last time of 7th day now displayed                  #
#        *tweaked regex to catch some programs it was missing       # 
# 0.2 -- +!showinfo trigger for detailed show info and next/last ep #
#        +!schedule for 7 day schedule                              #
#        *fixed errors in various regex                             #
# 0.1 -- Initial Release                                            #
#                                                                   #
# + added   - removed   * fixed/changed                             #
#####################################################################

########
# TODO #
#################################################
# *Move hardcoded settings to variables.        #
# *Add support for changing timezones.          #
# *Fix 'too long for line' problem              #
#################################################

### Begin Config ###

set tvrage(scheduleurl) "http://www.tvrage.com/quickschedule.php"
set tvrage(showinfourl) "http://www.tvrage.com/quickinfo.php"
set tvrage(scheduleTitle) "\00303New TV Shows for %%date%% ***All Times in EST/EDT***\00315"
set tvrage(c1) ""
set tvrage(c2) ""
set tvrage(c3) ""
set tvrage(c4) ""

### End Config ###

bind pub - !today pub:tvrage.com.today
bind pub - !tomorrow pub:tvrage.com.tomorrow
bind pub - !showinfo pub:tvrage.com.showinfo
bind pub - !schedule pub:tvrage.com.schedule

package require http
package require ncgi
setudef flag tv

proc pub:tvrage.com.schedule {nick uhost hand chan text} {
	set seconds [clock seconds]
	set days(sun) 0
	set days(mon) 1
	set days(tue) 2
	set days(wed) 3
	set days(thu) 4
	set days(fri) 5
	set days(sat) 6

	if ![info exist days([string tolower $text])] return 

	set currDay [clock format $seconds -format "%w"]
	
	if {$currDay > $days([string tolower $text])} {
		parse:tvrage.com $nick $uhost $hand $chan $text [expr (7 - $currDay) + $days([string tolower $text])]
	} else {
		parse:tvrage.com $nick $uhost $hand $chan $text [expr $days([string tolower $text]) - $currDay]
	}
}
		

proc pub:tvrage.com.today {nick uhost hand chan text} {
	parse:tvrage.com $nick $uhost $hand $chan $text "0"
}

proc pub:tvrage.com.tomorrow {nick uhost hand chan text} {
	parse:tvrage.com $nick $uhost $hand $chan $text "1"
}

proc parse:tvrage.com.encodeURL {str} {
	set str [string map {" " +} $str] 
	foreach c [split $str {}] {
	   if {$c == "+" || [string is alnum $c]} {append x $c} {
	      binary scan $c H2 c; append x %$c
	   }
	} 

	return $x
}

proc pub:tvrage.com.showinfo {nick uhost hand chan text} {
	if ![channel get $chan tv] return
	
	set token [http::geturl [join [list "http://www.tvrage.com/quickinfo.php?show=" [ncgi::encode [string trimleft $text]]] ""]]
	#set token [http::geturl [join [list "http://www.tvrage.com/quickinfo.php?show=" [parse:tvrage.com.encodeURL [string trimleft $text]]] ""]]
	set data [http::data $token]
	http::cleanup $token
	set show(title) ""
	
	foreach line [split $data \n] {
		if {[regexp {^No Show Results Were Found For \".*\"$} $line]} {
			putserv "PRIVMSG $chan :\00303$line\00315"
			return
		}
		if {[regexp {^Show Name@(.*)$} $line -> match]} { set show(title) $match }
		if {[regexp {^Show URL@(.*)$} $line -> match]} { set show(url) $match }
		if {[regexp {^Premiered@(.*)$} $line -> match]} { set show(premiered) $match }
		if {[regexp {^Latest Episode@(\d+)x(\d+)\^([\w\'\.\, \#\&\@\:\(\)]+)\^([\w\/]+)$} $line -> season episode eptitle epDate]} { 
			set show(latest) [join [list "\00303Latest Episode ::\00315 \00304$season" "x$episode - $eptitle ($epDate)\00315"] ""]
		}
		if {[regexp {^Next Episode@(\d+)x(\d+)\^([\w\'\.\, \#\@\&\:\(\)]+)\^([\w\/]+)$} $line -> season episode eptitle epDate]} { 
			set show(next) [join [list "\00303Next Episode ::\00315 \00304$season" "x$episode - $eptitle ($epDate)\00315"] ""]
		}
		if {[regexp {^Country@(.*)$} $line -> match]} { set show(country) $match }
		if {[regexp {^Status@(.*)$} $line -> match]} { set show(status) $match }
		if {[regexp {^Classification@(.*)$} $line -> match]} { set show(class) $match }
	}

	if ![info exist show(next)] { set show(next) "\00303Next Episode ::\00315 \00304N/A\00315" }

	putserv "PRIVMSG $chan :\00303Title ::\00315 \00304$show(title)\00315 \00308<>\00315 \00303URL ::\00315 \00304$show(url)\00315 \00308<>\00315 \00303Premiered ::\00315 \00304$show(premiered)\00315 \00308<>\00315 $show(latest) \00308<>\00315 $show(next) \00308<>\00315 \00303Country ::\00315 \00304$show(country)\00315 \00308<>\00315 \00303Status ::\00315 \00304$show(status)\00315"
}
		
proc parse:tvrage.com {nick uhost hand chan text when} {
	if ![channel get $chan tv] return
	set token [http::geturl http://www.tvrage.com/quickschedule.php]
	set data [http::data $token]
	http::cleanup $token
	set date ""
	set systemTime [clock seconds]
	set systemTime [expr $systemTime + 3600]
	set currentTime ""
	set parsing 0
	set currentOutput ""
	set gotTime 0
	set neededDate ""
	set neof 1

	set systemTime [expr "$systemTime + ($when * 86400)"]
	set neededDate [clock format $systemTime -format "%A, %d %b %Y"]

	foreach line [split $data \n] {
		if {[regexp {^\[DAY\]([\w\, ]+)\[\/DAY\]$} $line -> date]} {
			if {$parsing == 1} {
				break;
			}
			
			if {$date == $neededDate} {
				putserv "PRIVMSG $chan :\00303New TV Shows for $date ***All Times in EST/EDT***\00315"
				set parsing 1
			}
		}

		if {$parsing} {
			if {[regexp {^\[TIME\]([\w\: ]+)\[\/TIME\]$} $line -> currentTime]} {
				if {$gotTime} {
					set currentOutput [string trim $currentOutput <>]
					putserv "PRIVMSG $chan :$currentOutput"
					putlog $currentOutput
					set currentOutput ""
				}
			
				set currentOutput "\002$currentTime:\002 "
				set gotTime 1
			}

			regsub -all {\x92} $line {'} line
			if {[regexp {^\[SHOW\]([ \w\&\!]+)\^([\-\(\)\#\w \'\`\:&\!\/]+)\^([\dx]+)\^([\w\\\/\:\.\-]+)\[\/SHOW\]$} $line -> network title epnum url]} {
				set currentOutput [concat $currentOutput "\00304$network\00315 - \00314$title $epnum\00315 <>"]
			}
		}
	}

	if {$currentOutput != ""} {
		set currentOutput [string trim $currentOutput <>]
		putserv "PRIVMSG $chan :$currentOutput"
	}
}

putlog "TVRage.com Primetime Schedule v0.5"
T
Tammik
Voice
Posts: 10
Joined: Mon Jan 23, 2006 9:41 am

Post by Tammik »

have you enable ncgi again.. ???
thouht you removed that ?
G
GaveUp
Op
Posts: 139
Joined: Thu Jan 19, 2006 3:56 am

Post by GaveUp »

Whoops. I was doing some testing and switching back and forth on it and forgot to set it back before pasting the script over. Just search the script for 'ncgi' and comment those two lines out. On the second line (the one that starts "set token...") uncomment the line below it.
T
Tammik
Voice
Posts: 10
Joined: Mon Jan 23, 2006 9:41 am

Post by Tammik »

found a bug..

script wont work if you type !showinfo 24


i get this then

Tcl error [pub:tvrage.com.showinfo]: can't read "show(latest)": no such element in array
Post Reply