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 

TVMaze Script That lists tonights shows

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
BarGuy
Voice


Joined: 20 Aug 2019
Posts: 24

PostPosted: Tue Mar 14, 2023 2:42 pm    Post subject: TVMaze Script That lists tonights shows Reply with quote

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
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1108
Location: France

PostPosted: Tue Mar 14, 2023 6:51 pm    Post subject: Re: TVMaze Script That lists tonights shows Reply with quote

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


Joined: 20 Aug 2019
Posts: 24

PostPosted: Tue Mar 14, 2023 7:49 pm    Post subject: Re: TVMaze Script That lists tonights shows Reply with quote

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
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1191

PostPosted: Tue Mar 14, 2023 10:30 pm    Post subject: Re: TVMaze Script That lists tonights shows Reply with quote

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! Wink

( Tip #1 : Start with something *really* simple. )


We can't make you want to. But that's all you really need, to get started. Smile

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.
Smile
_________________
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
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3767
Location: Mint Factory

PostPosted: Wed Mar 15, 2023 12:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
BarGuy
Voice


Joined: 20 Aug 2019
Posts: 24

PostPosted: Wed Mar 15, 2023 9:11 pm    Post subject: Re: TVMaze Script That lists tonights shows Reply with quote

willyw wrote:
... We can give you links to bookmark for quick reference.


That would be greatly appreciated Thx
Back to top
View user's profile Send private message
BarGuy
Voice


Joined: 20 Aug 2019
Posts: 24

PostPosted: Wed Mar 15, 2023 9:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 826
Location: Tennessee, USA

PostPosted: Wed Mar 15, 2023 9:50 pm    Post subject: AI bots are far from smart Reply with quote

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


Joined: 20 Aug 2019
Posts: 24

PostPosted: Wed Mar 15, 2023 9:54 pm    Post subject: Re: AI bots are far from smart Reply with quote

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
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 826
Location: Tennessee, USA

PostPosted: Wed Mar 15, 2023 9:56 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1191

PostPosted: Wed Mar 15, 2023 10:30 pm    Post subject: Re: TVMaze Script That lists tonights shows Reply with quote

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. Smile 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. Smile
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 ! Smile

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 ...
Smile

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
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1108
Location: France

PostPosted: Thu Mar 16, 2023 7:28 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests 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