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.

Script show time left between two dates

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
t
tigrato
Voice
Posts: 22
Joined: Sat Jul 04, 2009 7:46 am

Script show time left between two dates

Post by tigrato »

I wanted a code that would make the subtraction between two dates using tv a script.
The next episode of Sons of Anarchy is Oiled[S03E02], it airs on 2010-09-14 [6 days from now]
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

Post by blake »

Check out the countdown scripts in the tcl archives they could do what you want try date.tcl

http://www.egghelp.org/tclhtml/3478-4-0 ... ntdown.htm
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

Code: Select all

bind pub - !test countdown

proc countdown { nickname hostname handle channel arg } {
#unixtime stamp for 09/08/2010 @ 17:00, 4 weeks back
set date1 "1281369600" 

		# finds the time and date now
        	set now [unixtime] 
		# counts the time passed scince now
		incr now -$date1 
		# shows how long has passed since $date1
		set then [duration $now]

	puthelp "PRIVMSG $channel :date1 was: $then ago, $nickname | \([clock format $date1 -format %d.%m.%Y] @ [clock format $date1 -format %H:%M:%S]\)"	
		
		}
this is just an example explaining how to do what i think you mean, with unixtime timestamps

output to channel

Code: Select all

 [16:21] <doggo> !test
[16:21] <inner-SaNcTuM> date1 was: 4 weeks 1 day 23 hours 21 minutes 49 seconds ago, doggo | (09.08.2010 @ 17:00:00)

hope this helps you figure something out :)
t
tigrato
Voice
Posts: 22
Joined: Sat Jul 04, 2009 7:46 am

Post by tigrato »

Solved. But how to remove the hours, minutes and seconds?
6 days 5 hours 40 minutes 6 seconds from now
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

Code: Select all

proc countdown { nickname hostname handle channel arg } { 
set date1 "1281369600" 
        set now [unixtime] 
      	incr now -$date1 
      	set then [duration $now] 
	regsub -all {year*s} $then "" then
	regsub -all {week*s} $then "" then
	regsub -all {day*s} $then "" then
	regsub -all {hour*s} $then "" then
	regsub -all {minute*s} $then "" then
	regsub -all {second*s} $then "" then
   
puthelp "PRIVMSG $channel :date1 was: $then | \([clock format $date1 -format %d.%m.%Y] @ [clock format $date1 -format %H:%M:%S]\)"    
       }

Code: Select all

[13:31] <doggo> !test
[13:31] <inner-SaNcTuM> date1 was: 4  2  20  31  12 | (09.08.2010 @ 17:00:00))
ive never wanted to remove them parts but that seems to work, also i dont know much about regsub if theres a simpler way id like to know too :)
t
tigrato
Voice
Posts: 22
Joined: Sat Jul 04, 2009 7:46 am

Post by tigrato »

doggo you dont understand sorry

[1 week 5 days from now] instead[ 1 week 5 days 13 hours 39 minutes 35 seconds from now]
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

tigrato wrote: [1 week 5 days from now] instead[ 1 week 5 days 13 hours 39 minutes 35 seconds from now]
If I understood what you wanted it to do, then adding one line to doggo's oringal script will do it:

Code: Select all


# original script here:  http://forum.egghelp.org/viewtopic.php?p=94273#94273

bind pub - !test countdown

proc countdown { nickname hostname handle channel arg } {
#unixtime stamp for 09/08/2010 @ 17:00, 4 weeks back
set date1 "1281369600"

      # finds the time and date now
           set now [unixtime]
      # counts the time passed scince now
      incr now -$date1
      # shows how long has passed since $date1
      set then [duration $now]

set then "[lrange [split $then] 0 3]"

   puthelp "PRIVMSG $channel :date1 was: $then ago, $nickname | \([clock format $date1 -format %d.%m.%Y] @ [clock format $date1 -format %H:%M:%S]\)"   
      
      }

Produces this in the channel:

<botnick> date1 was: 4 weeks 2 days ago, testnick | (09.08.2010 @ 12:00:00)


Is that it?
t
tigrato
Voice
Posts: 22
Joined: Sat Jul 04, 2009 7:46 am

Post by tigrato »

yes. Thanks everyone.
t
tigrato
Voice
Posts: 22
Joined: Sat Jul 04, 2009 7:46 am

Post by tigrato »

hi,

How can i add one hour? like this
Example: 6 days 5 hours 40 minutes 6 seconds from now
I need: 6 days 6 hours 40 minutes 6 seconds from now

i need time in UTC (GMT+1) and tvrage have in GMT+0
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

tigrato wrote:hi,

How can i add one hour? like this
Example: 6 days 5 hours 40 minutes 6 seconds from now
I need: 6 days 6 hours 40 minutes 6 seconds from now

i need time in UTC (GMT+1) and tvrage have in GMT+0

Code: Select all

set my_time_in_gmt [clock scan [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S %Z"] -gmt 1]]
set time_til_airs [duration [expr {$time_show_airs - $my_time_in_gmt}]]
This will convert your time to GMT. Use this type of logic to do math against tvrage instead of merely [clock seconds] or [unixtime]. It should do this by default. This sounds like a flaw within tvrage itself IMO. It fails to arrive at proper "durations until" because it isn't converting bot timestamps to GMT before comparing against the show's air time in GMT. Pretty simple to add using my code above. ;)
t
tigrato
Voice
Posts: 22
Joined: Sat Jul 04, 2009 7:46 am

Post by tigrato »

I didn't get it working...


My script:

Code: Select all

proc dlx:tvrage:next { nick host hand chan arg } {
    global tvrage
    package require http
    set arg [string map { " " "_" } $arg]
 
    set url "http://services.tvrage.com/tools/quickinfo.php?show=$arg"
    set page [http::data [http::geturl $url -timeout $tvrage(timeout)]]
 
    regexp {Show Name@([A-Za-z 0-9\&\':\,]+)} $page gotname show_name
    set gotnext [ regexp {Next Episode@([0-9x]+)\^([A-Za-z0-9 -\`\"\'\&:.,]+)\^([A-Za-z0-9/]+)/([0-9]+)/([0-9]+)} $page gotnext next_ep next_ep_title next_ep_date1 next_ep_date2 next_ep_date3]
     set gotunix1 [ regexp {NODST@([0-9]+)} $page gotunix gotunix2 ]
    regexp {Airtime@([A-Za-z, 0-9:]+)} $page gotairtime show_airtime


    if { ![info exists show_name] } {
       putquick "PRIVMSG $chan :Error! (timeout or something similar)"
    #   return -1
    }

    if { $gotnext == 0 } {
      putquick "PRIVMSG $chan :The next episode of \002$show_name\002 is not yet scheduled."
    } else {
           set now [unixtime]
              incr gotunix2 -$now 

                  set timeleft [duration $gotunix2]

     
   putquick "PRIVMSG $chan :The next episode of \002$show_name\002 is \002$next_ep_title \[$next_ep\]\002, it will air on \002$next_ep_date2-$next_ep_date1-$next_ep_date3\002 \[\002$timeleft from now\002\]"
   }
}
Someone can help?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

proc dlx:tvrage:next { nick host hand chan arg } {
    global tvrage
    package require http
    set arg [string map { " " "_" } $arg]
 
    set url "http://services.tvrage.com/tools/quickinfo.php?show=[http::formatQuery $arg]"
    set page [http::data [set token [http::geturl $url -timeout $tvrage(timeout)]]]
    ::http::cleanup $token
 
    regexp {Show Name@([A-Za-z 0-9\&\':\,]+)} $page gotname show_name
    set gotnext [ regexp {Next Episode@([0-9x]+)\^([A-Za-z0-9 -\`\"\'\&:.,]+)\^([A-Za-z0-9/]+)/([0-9]+)/([0-9]+)} $page gotnext next_ep next_ep_title next_ep_date1 next_ep_date2 next_ep_date3]
     set gotunix1 [ regexp {NODST@([0-9]+)} $page gotunix gotunix2 ]
    regexp {Airtime@([A-Za-z, 0-9:]+)} $page gotairtime show_airtime


    if { ![info exists show_name] } {
       putquick "PRIVMSG $chan :Error! (timeout or something similar)"
    #   return -1
    }

    if { $gotnext == 0 } {
      putquick "PRIVMSG $chan :The next episode of \002$show_name\002 is not yet scheduled."
    } else {
      # get a clean unix timestamp in GMT
      set now [clock scan [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S %Z"] -gmt 1]]
      # compare GMT timestamps, remove hours,minutes,seconds
      # generate duration until.
      set timeleft [duration [expr {($gotunix2 - $now) - (($gotunix2 - $now) % 86400)}]]     
      putquick "PRIVMSG $chan :The next episode of \002$show_name\002 is \002$next_ep_title \[$next_ep\]\002, it will air on \002$next_ep_date2-$next_ep_date1-$next_ep_date3\002 \[\002$timeleft from now\002\]"
   }
}
Something like that eh? :)
This is timezone independent. The script automatically adjusts your timezone to GMT. This will not work on FreeBSD (it will work on anything else), as there is a known issue with UTC timestamps given when UTC was not requested. There is a work-around for FreeBSD as well which is equally simple. This code is also tcl8.4 friendly so works on past/present/future bots as well.
Post Reply