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 

Script show time left between two dates

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


Joined: 04 Jul 2009
Posts: 22

PostPosted: Wed Sep 08, 2010 8:48 am    Post subject: Script show time left between two dates Reply with quote

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]
Back to top
View user's profile Send private message
blake
Master


Joined: 23 Feb 2009
Posts: 201

PostPosted: Wed Sep 08, 2010 10:40 am    Post subject: Reply with quote

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-0-1-countdown.htm
_________________
Blake
UKEasyHosting UKStormWatch
Back to top
View user's profile Send private message Visit poster's website
doggo
Halfop


Joined: 05 Jan 2010
Posts: 97

PostPosted: Wed Sep 08, 2010 11:34 am    Post subject: Reply with quote

Code:
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:
 [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 Smile
_________________
NON geeky!! http://gotcode4u.com/
Back to top
View user's profile Send private message Visit poster's website
tigrato
Voice


Joined: 04 Jul 2009
Posts: 22

PostPosted: Wed Sep 08, 2010 2:21 pm    Post subject: Reply with quote

Solved. But how to remove the hours, minutes and seconds?
6 days 5 hours 40 minutes 6 seconds from now
Back to top
View user's profile Send private message
doggo
Halfop


Joined: 05 Jan 2010
Posts: 97

PostPosted: Thu Sep 09, 2010 8:38 am    Post subject: Reply with quote

Code:
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:
[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 Smile
_________________
NON geeky!! http://gotcode4u.com/
Back to top
View user's profile Send private message Visit poster's website
tigrato
Voice


Joined: 04 Jul 2009
Posts: 22

PostPosted: Thu Sep 09, 2010 9:15 am    Post subject: Reply with quote

doggo you dont understand sorry

[1 week 5 days from now] instead[ 1 week 5 days 13 hours 39 minutes 35 seconds from now]
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Thu Sep 09, 2010 10:35 am    Post subject: Reply with quote

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:


# 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?
Back to top
View user's profile Send private message
tigrato
Voice


Joined: 04 Jul 2009
Posts: 22

PostPosted: Thu Sep 09, 2010 6:05 pm    Post subject: Reply with quote

yes. Thanks everyone.
Back to top
View user's profile Send private message
tigrato
Voice


Joined: 04 Jul 2009
Posts: 22

PostPosted: Sun Oct 17, 2010 12:20 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Oct 17, 2010 1:28 pm    Post subject: Reply with quote

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:
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. Wink
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
tigrato
Voice


Joined: 04 Jul 2009
Posts: 22

PostPosted: Sun Oct 17, 2010 2:40 pm    Post subject: Reply with quote

I didn't get it working...


My script:

Code:
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?
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Oct 17, 2010 2:53 pm    Post subject: Reply with quote

Code:
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? Smile
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.
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
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