View previous topic :: View next topic |
Author |
Message |
BarGuy Voice
Joined: 20 Aug 2019 Posts: 24
|
Posted: Tue Mar 14, 2023 2:42 pm Post subject: TVMaze Script That lists tonights shows |
|
|
so was playing around with OpenAI (as I have zero clue how to create scriptes) to see if it could create a tcl using a tvmaze public API key with the trigger !tonight to list upcoming tv shows during primetime in a channel.
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: |
# 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"
}
}
} |
Last edited by BarGuy on Wed Mar 15, 2023 10:05 pm; edited 1 time in total |
|
Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1108 Location: France
|
Posted: Tue Mar 14, 2023 6:51 pm Post subject: Re: TVMaze Script That lists tonights shows |
|
|
BarGuy wrote: | so was playing around with OpenAI (as I have zero clue how to create scriptes) to see if it could create a tcl |
LOL.
This is my very own opinion, but I'm not here to correct scripts from a pseudo-IA, I'm here to help people to learn how to script.
And as I'm a cool guy, I'll give you a small tip: global namespace. _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
Back to top |
|
 |
BarGuy Voice
Joined: 20 Aug 2019 Posts: 24
|
Posted: Tue Mar 14, 2023 7:49 pm Post subject: Re: TVMaze Script That lists tonights shows |
|
|
Quote: |
LOL.
This is my very own opinion, but I'm not here to correct scripts from a pseudo-IA, I'm here to help people to learn how to script.
And as I'm a cool guy, I'll give you a small tip: global namespace. |
Like I said, I was just playing around.. Trying something different with new tech.
And PS having to say you are a "cool guy" makes you NOT a cool guy |
|
Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1191
|
Posted: Tue Mar 14, 2023 10:30 pm Post subject: Re: TVMaze Script That lists tonights shows |
|
|
BarGuy wrote: | ... (as I have zero clue how to create scriptes)...
|
Want to get started, playing around writing some simple scripts?
To start to get the hang of it?
We can give you links to bookmark for quick reference.
When you hit a snag, we can perhaps save you time in digging through them all, and point you to what you need to read, to be able to get going again.
Heck, there's even a website that is a beginner's course in TCL for Eggdrop, that is designed to get one started, from knowing nothing.
Speaking of fun - it IS fun, when stuff that you write from scratch, actually works!
( Tip #1 : Start with something *really* simple. )
We can't make you want to. But that's all you really need, to get started.
If you do decide that it would be fun to start messing around with the basics, just say the word.
Best of luck with it, whatever you decide.
 _________________ For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia ! |
|
Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3767 Location: Mint Factory
|
Posted: Wed Mar 15, 2023 12:21 pm Post subject: |
|
|
In layman terms, the error states that the 'tvmaze_api_key' variable isn't 'available' for the 'tonight' function (meaning 'proc tonight').
To extrapolate and give a real life example is like you are in a room without any door or windows towards outside and you can't tell if it's day or night outside. Now, if you would have access to a window you could tell it's day, night or whatever.
The 'window' in the above example is the 'global' thing that CrazyCat hinted about. Basically before the: "# Get the current date and time in Eastern time zone " line add:
Code: |
global tvmaze_api_key
|
and rehash the bot. _________________ Once the game is over, the king and the pawn go back in the same box. |
|
Back to top |
|
 |
BarGuy Voice
Joined: 20 Aug 2019 Posts: 24
|
Posted: Wed Mar 15, 2023 9:11 pm Post subject: Re: TVMaze Script That lists tonights shows |
|
|
willyw wrote: | ... We can give you links to bookmark for quick reference.
|
That would be greatly appreciated Thx |
|
Back to top |
|
 |
BarGuy Voice
Joined: 20 Aug 2019 Posts: 24
|
Posted: Wed Mar 15, 2023 9:12 pm Post subject: |
|
|
caesar wrote: | . Basically before the: "# Get the current date and time in Eastern time zone " line add:
Code: |
global tvmaze_api_key
|
and rehash the bot. |
Tried.. got the same error. Thanks for taking a look |
|
Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 826 Location: Tennessee, USA
|
Posted: Wed Mar 15, 2023 9:50 pm Post subject: AI bots are far from smart |
|
|
You have all the same code repeated twice in your script!
Remove all of the duplicate code, then apply the global fix as posted by CrazyCat & caesar to the remaining code.
That will clear the first error you posted above. _________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
. |
|
Back to top |
|
 |
BarGuy Voice
Joined: 20 Aug 2019 Posts: 24
|
Posted: Wed Mar 15, 2023 9:54 pm Post subject: Re: AI bots are far from smart |
|
|
SpiKe^^ wrote: | You have all the same code repeated twice in your script!
|
I looked at my actual eggdrop script file and its not duped, must have just be a double paste on my part here |
|
Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 826 Location: Tennessee, USA
|
Posted: Wed Mar 15, 2023 9:56 pm Post subject: |
|
|
Well then Caesar's "global tvmaze_api_key" line will clear that error... _________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
. |
|
Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1191
|
Posted: Wed Mar 15, 2023 10:30 pm Post subject: Re: TVMaze Script That lists tonights shows |
|
|
BarGuy wrote: | willyw wrote: | ... We can give you links to bookmark for quick reference.
|
That would be greatly appreciated Thx |
TCL is a stand alone scripting language. Eggdrop just uses it. And, the Eggdrop people have thus created some Eggdrop specific stuff.
This the Eggdrop specific TCL page:
https://docs.eggheads.org/using/tcl-commands.html
This is the rest of TCL:
https://www.tcl.tk/man/tcl8.6/TclCmd/contents.html
For example, the thing that you have been discussing - the global command - can be found there.
https://www.tcl.tk/man/tcl8.6/TclCmd/global.html
I hope that your eyes don't glaze over, when you look at that page. Things can go way in depth on that site. But at times, that's necessary. Other times, you can get the info explained to you, right here - in simpler and shorter terms.
This is a course in TCL for Eggdrop. It is designed to help the beginner that knows nothing about it, to get started.
http://suninet.the-demon.de/
It is a very old page. So what?... the info is still good.
Start at the beginning, and go through it, section by section. It takes you by the hand, and guides you.
I suggest that at any time as you are going through it, that when you hit something that is not fully clear, or just looks to be fun, to stop and go write some code and load it in your bot, and play with it !
I suggest that if at all possible, you have a spare bot up and running, that is not performing any functions that you care about, such that you can use it to test code on. This way, when you crash it, it's no big deal. And you WILL crash it. Don't ask me how I know ...
With those three links, you can not only get started, but you can do a LOT !
Start with something so simple that it is almost silly. Like having the bot respond with something when you do:
!hello
Then perhaps move on to having the bot greet you when you join a channel with it.
These sort of things will get you used to the most very basic things. Then... you build your skill from there.
Write code ... and when you get stumped, you can post it on this forum under Scripting Help. Somebody will come along and point out the goof, and tell you what to read up on, so you can fix it.
Annnnnnd ... away you go !
Have fun!
I hope this helps. _________________ For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia ! |
|
Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1108 Location: France
|
Posted: Thu Mar 16, 2023 7:28 am Post subject: |
|
|
caesar wrote: | The 'window' in the above example is the 'global' thing that CrazyCat hinted about. Basically before the: "# Get the current date and time in Eastern time zone " line add:
Code: |
global tvmaze_api_key
|
and rehash the bot. |
My preference goes to not use global (too easy to forget a variable) and name the variable with its namespace:
Code: | set response [http::geturl $url -headers [list "X-TVMaze-API-Key" $::tvmaze_api_key]] |
_________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
Back to top |
|
 |
|