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.

TVMaze Script That lists tonights shows

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
B
BarGuy
Voice
Posts: 24
Joined: Tue Aug 20, 2019 3:27 pm

TVMaze Script That lists tonights shows

Post by BarGuy »

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: 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"
    }
}


}
Last edited by BarGuy on Wed Mar 15, 2023 10:05 pm, edited 1 time in total.
User avatar
CrazyCat
Revered One
Posts: 1304
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: TVMaze Script That lists tonights shows

Post by CrazyCat »

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.
B
BarGuy
Voice
Posts: 24
Joined: Tue Aug 20, 2019 3:27 pm

Re: TVMaze Script That lists tonights shows

Post by BarGuy »

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
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Re: TVMaze Script That lists tonights shows

Post by willyw »

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 !
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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: Select all

global tvmaze_api_key
and rehash the bot.
Once the game is over, the king and the pawn go back in the same box.
B
BarGuy
Voice
Posts: 24
Joined: Tue Aug 20, 2019 3:27 pm

Re: TVMaze Script That lists tonights shows

Post by BarGuy »

willyw wrote:... We can give you links to bookmark for quick reference.
That would be greatly appreciated Thx
B
BarGuy
Voice
Posts: 24
Joined: Tue Aug 20, 2019 3:27 pm

Post by BarGuy »

caesar wrote:. Basically before the: "# Get the current date and time in Eastern time zone " line add:

Code: Select all

global tvmaze_api_key
and rehash the bot.
Tried.. got the same error. Thanks for taking a look
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

AI bots are far from smart

Post by SpiKe^^ »

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
.
B
BarGuy
Voice
Posts: 24
Joined: Tue Aug 20, 2019 3:27 pm

Re: AI bots are far from smart

Post by BarGuy »

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
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

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
.
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Re: TVMaze Script That lists tonights shows

Post by willyw »

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 !
User avatar
CrazyCat
Revered One
Posts: 1304
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

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: Select all

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: Select all

set response [http::geturl $url -headers [list "X-TVMaze-API-Key" $::tvmaze_api_key]]
H
Henkie2
Voice
Posts: 35
Joined: Fri Sep 25, 2015 2:55 pm

Re: TVMaze Script That lists tonights shows

Post by Henkie2 »

He nice one, was looking for this.
Got it working only i'm a retard how can i make it to call it as https?

I added this:

package require http
package require tls

proc tvmazetoday {nick uhost hand chan text} {
http::register https 443 [list ::tls::socket]

url as https://
http::unregister https

Only than it's not parsing the data :D
Any one can give me a advice? Thx

Edit: And how to add a extra day? To get trigger !tomorrow available?
User avatar
CrazyCat
Revered One
Posts: 1304
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: TVMaze Script That lists tonights shows

Post by CrazyCat »

Quick solution for https: use this kind of register:
http::register https 443 [list ::tls::socket -autoservername true]
Paste your script and I'll have a try soon
H
Henkie2
Voice
Posts: 35
Joined: Fri Sep 25, 2015 2:55 pm

Re: TVMaze Script That lists tonights shows

Post by Henkie2 »

CrazyCat wrote: Tue Dec 12, 2023 6:51 pm Quick solution for https: use this kind of register:
http::register https 443 [list ::tls::socket -autoservername true]
Paste your script and I'll have a try soon
He thx, will have a look. This is wat i did and for sure code can be better.
(need to define the sets outside the proc etc, only i'm not a coder as well)
Right now it's not working if i use the https like this. (set url to http and it works)

Todo: (Someone can help on this? thx)
- from http to https API call
- set defines outside proc tvmazetoday (for use on new triggers: !tomorrow, !todaystream etc)
- timezone not really working + or- not really give diff in results
- trigger: !tomorrow trigger add extra day to $currdate (How todo?)
- trigger: !todaystreams get webstreams page data (date from hulu,disney+, netflix etc)
url = http://api.tvmaze.com/schedule/web?date ... country=US
regex/json needs to be checked on this to get correct network etc (can anyone help me?)

Code: Select all

# -----------------------------------
# TVMaze TV !today API Announce
# -----------------------------------

   # Define the !today/!tonight command
   bind pub - "!today" tvmazetoday
   bind pub - "!tonight" tvmazetoday
   bind time - "* 00 * * *" tvmazetoday
   #bind pub - "!tomorrow" tvmazetomorrow (need to add extra day firts from $currdate)

proc tvmazetoday {nick uhost hand chan text} {
package require http
package require tls
http::register https 443 [list ::tls::socket -autoservername true]
   
   # Channel to show upcoming tv shows
   set chan "#channelhere"

   # Get your tvmaze api key: 
   set tvmaze_api_key "YOUR_KEY_HERE"

   # Define the networks we're interested in
   set networks [list "AMC" "FOX" "FX" "SyFy" "Travel" "HBOMAX" "CW" "Starz" "TLC" "Showtime" "KTLA" "NBC" "CBS" "ABC"]
   
    # Get the current date and time in Eastern time zone
    set timezone +6
    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]

    # Fetch the TV shows for the current date
    set url "https://api.tvmaze.com/schedule?$currdate&country=US"
    set response [http::geturl $url -headers [list "X-TVMaze-API-Key" $tvmaze_api_key] -timeout 10000]
    set json_data [json::json2dict [http::data $response]]
    http::unregister https
    http::cleanup $response

    # Filter the TV shows by time and network
    set shows {}
    foreach item $json_data {
        set airtime [dict get $item "airtime"]
        set season [dict get $item "season"]
        set number [dict get $item "number"]
        set network [dict get [dict get $item "show"] "network" "name"]
        set name [dict get [dict get $item "show"] "name"]
        if {[lsearch -exact $networks $network] != -1} {
            lappend shows [format "%s %s (S%sE%s) - %s" $airtime $name $season $number $network]
        }
    }

    # If no shows were found, display a message
    if {[llength $shows] == 0} {
        putquick "PRIVMSG $chan :TVMAZE: Today's TV Shows:"
        putquick "PRIVMSG $chan :00:00 No TV shows found for tonight"
        return
    }

    # List the TV shows in the channel
    putquick "PRIVMSG $chan :TVMAZE: Today's TV Shows:"
    foreach show $shows {
        putquick "PRIVMSG $chan :$show"
    }
}
Post Reply