| View previous topic :: View next topic |
| Author |
Message |
tigrato Voice
Joined: 04 Jul 2009 Posts: 22
|
Posted: Wed Sep 08, 2010 8:48 am Post subject: Script show time left between two dates |
|
|
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 |
|
 |
blake Master
Joined: 23 Feb 2009 Posts: 201
|
|
| Back to top |
|
 |
doggo Halfop
Joined: 05 Jan 2010 Posts: 97
|
Posted: Wed Sep 08, 2010 11:34 am Post subject: |
|
|
| 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  _________________ NON geeky!! http://gotcode4u.com/ |
|
| Back to top |
|
 |
tigrato Voice
Joined: 04 Jul 2009 Posts: 22
|
Posted: Wed Sep 08, 2010 2:21 pm Post subject: |
|
|
Solved. But how to remove the hours, minutes and seconds?
6 days 5 hours 40 minutes 6 seconds from now |
|
| Back to top |
|
 |
doggo Halfop
Joined: 05 Jan 2010 Posts: 97
|
Posted: Thu Sep 09, 2010 8:38 am Post subject: |
|
|
| 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  _________________ NON geeky!! http://gotcode4u.com/ |
|
| Back to top |
|
 |
tigrato Voice
Joined: 04 Jul 2009 Posts: 22
|
Posted: Thu Sep 09, 2010 9:15 am Post subject: |
|
|
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 |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Thu Sep 09, 2010 10:35 am Post subject: |
|
|
| 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 |
|
 |
tigrato Voice
Joined: 04 Jul 2009 Posts: 22
|
Posted: Thu Sep 09, 2010 6:05 pm Post subject: |
|
|
| yes. Thanks everyone. |
|
| Back to top |
|
 |
tigrato Voice
Joined: 04 Jul 2009 Posts: 22
|
Posted: Sun Oct 17, 2010 12:20 pm Post subject: |
|
|
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 |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Oct 17, 2010 1:28 pm Post subject: |
|
|
| 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.  _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
tigrato Voice
Joined: 04 Jul 2009 Posts: 22
|
Posted: Sun Oct 17, 2010 2:40 pm Post subject: |
|
|
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 |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Oct 17, 2010 2:53 pm Post subject: |
|
|
| 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?
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 |
|
 |
|