I get the following error:
Tcl error [tonight]: can't read "tvmaze_api_key": no such variable
can't read "tvmaze_api_key": no such variable
while executing
"list "X-TVMaze-API-Key" $tvmaze_api_key"
(procedure "tonight" line 13)
invoked from within
"tonight $_pub1 $_pub2 $_pub3 $_pub4 $_pub5"
Any help tweaking this to work, if its even possible to make this script workable would be greatly appreciated.
Here is the script that it created:
Code: Select all
# Set your TVMaze API key here
set tvmaze_api_key "YOUR_API_KEY_HERE" (of course in the actual running script my api key is here)
# Define the !tonight command
bind pub - "!tonight" tonight
# The tonight command handler
proc tonight {nick uhost hand chan text} {
# Get the current date and time in Eastern time zone
set timezone -5
set currtime [clock add [clock seconds] $timezone minutes]
set currdate [clock format $currtime -format %Y-%m-%d]
set currtime [clock format $currtime -format %H:%M:%S]
# Define the networks we're interested in
set networks [list "ABC" "CBS" "NBC" "FOX" "The CW" "KTLA" "AMC" "HBOMAX" "Showtime"]
# Fetch the TV shows for the current date
set url "http://api.tvmaze.com/schedule?country=US&date=$currdate"
set response [http::geturl $url -headers [list "X-TVMaze-API-Key" $tvmaze_api_key]]
set json_data [json::json2dict [http::data $response]]
http::cleanup $response
# Filter the TV shows by time and network
set shows {}
foreach item $json_data {
set airtime [dict get $item "airtime"]
set network [dict get [dict get $item "show"] "network" "name"]
set name [dict get [dict get $item "show"] "name"]
if {$airtime ge "20:00:00" && $airtime le "22:00:00" && [lsearch -exact $networks $network] != -1} {
lappend shows [format "{\0034%s\003} %s (%s)" $name $airtime $network]
}
}
# If no shows were found, display a message
if {[llength $shows] == 0} {
putquick "PRIVMSG $chan :No TV shows found for tonight."
return
}
# List the TV shows in the channel
putquick "PRIVMSG $chan :\0034Upcoming TV shows for tonight:\003"
foreach show $shows {
putquick "PRIVMSG $chan :$show"
}
}
}