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 

convert unixtime into human readable time[SOLVED]
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
speechles
Revered One


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

PostPosted: Sun Jun 01, 2008 4:27 pm    Post subject: Reply with quote

ztian299 wrote:
I have converted it into human readable format And it's right.

....

Let me guess. The format time uses isn't clock seconds (just numbers), but some combination of who knows what that you've never made us aware until this point... *slams face into keyboard*
_________________
speechles' eggdrop tcl archive


Last edited by speechles on Sun Jun 01, 2008 4:27 pm; edited 1 time in total
Back to top
View user's profile Send private message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Sun Jun 01, 2008 4:27 pm    Post subject: Reply with quote

Quote:

Tcl error [pub:nickinfo]: syntax error in expression "1212352944 - ": premature end of expression

the unixtime indicates the time for the specific user. But what is wrong with that expression?
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 Jun 01, 2008 4:29 pm    Post subject: Reply with quote

ztian299 wrote:
Quote:

Tcl error [pub:nickinfo]: syntax error in expression "1212352944 - ": premature end of expression

the unixtime indicates the time for the specific user. But what is wrong with that expression?


also, that unixtime isnt for the user.. haw.. time is NEVER retrieved because you failed to disclose it's contents (numbers/letters/etc).

It's expecting a numeric sequence of elapsed seconds (time) to be subtracted from (unitime/clock seconds). Isn't it painfully obvious what's wrong? *face slams into keyboard again* If your feeding it some human readable format for time.. then yeah, enjoy much syntax errors. Because it will null the value (time) if it isnt fully numeric (since used in a numeric fashion). Hence your error. Until you disclose how your (time) is formatted for human readability, we are quagmired.

Quote:

.tcl set example1 1440
.tcl set example2 ""
.tcl set result [expr $example1-$example2]
> Tcl error: syntax error in expression "1440 - ": premature end of expression


This is your scenario.

Edit: read above notice the missing example2, this is your time.
_________________
speechles' eggdrop tcl archive


Last edited by speechles on Sun Jun 01, 2008 4:42 pm; edited 2 times in total
Back to top
View user's profile Send private message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Sun Jun 01, 2008 4:36 pm    Post subject: Reply with quote

Quote:

Tcl error [pub:nickinfo]: syntax error in expression "1212352944 - ": premature end of expression

the unixtime indicates the time for the specific user. But what is wrong with that expression?

the unixtime is added to MySQL by
Code:

set time [unixtime]

So not MY fault TCL makes it NOT readable?
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 Jun 01, 2008 4:38 pm    Post subject: Reply with quote

ztian299 wrote:
Quote:

Tcl error [pub:nickinfo]: syntax error in expression "1212352944 - ": premature end of expression

the unixtime indicates the time for the specific user. But what is wrong with that expression?

the unixtime is added to MySQL by
Code:

set time [unixtime]

So not MY fault TCL makes it NOT readable?


Until you post your entire script, or segments of it explaining more. All your doing is confusing me. So adieu, chow, adios.. hope to see [code]stuff in here[/code] posted by you soon.
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Sun Jun 01, 2008 4:42 pm    Post subject: Reply with quote

I'm trying to make TCL calculate the time between the specific unixtime and the time that is right NOW. and then make a output like:
'4weeks 3days 2hours 1minute'
but as i see. It should not be easy!
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 Jun 01, 2008 4:46 pm    Post subject: Reply with quote

ztian299 wrote:
I'm trying to make TCL calculate the time between the specific unixtime and the time that is right NOW. and then make a output like:
'4weeks 3days 2hours 1minute'
but as i see. It should not be easy!
Code:
set time [unixtime]
putserv "PRIVMSG $chan :[duration [expr [clock seconds] - $time]]"


can you tell me what the output of this would be? Let's say the actual time it is now, is 13200 in seconds (it isn't we just say this). Now the first line is 'set time 13200'. Now in the message we take the difference betweeen clock seconds and 13200. Clock seconds will return the exact number of elapsed seconds at that moment, perhaps since its running after we set time, this is 13201. Now you have it take 13201-13200, and you get 1 second.

You fail to understand this. Unless you have a starting point in time, to subtract from your current time. You cannot do what you want.

[unixtime] == [clock seconds] == time it is right now

If you simply want to adjust for timezones, use clock format and within it an expr to subtract/add hours accordingly.
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Jun 01, 2008 4:52 pm    Post subject: Reply with quote

@ztian299:
Your foreach-loop expects you to use -flatlist with mysqlsel rather than -list. Change that, and everything should work with some code posted way up.

Code:
...
set nick [lindex [split $text] 0]
set search [mysqlsel $dbconnect "SELECT nick,fname,lname,info,time FROM table WHERE nick LIKE '$nick%' LIMIT 2" -flatlist]
foreach {nick fname lname info time} $search {
      putserv "PRIVMSG $chan :$nick - Firstname: $fname Lastname: $lname Info: $info - Added [duration [expr [clock seconds] - $time]] ago"
}
...


Another option would be to modify your foreach-loop:
Code:
...
set nick [lindex [split $text] 0]
set search [mysqlsel $dbconnect "SELECT nick,fname,lname,info,time FROM table WHERE nick LIKE '$nick%' LIMIT 2" -list]
foreach {row} $search {
      putserv "PRIVMSG $chan :[lindex $row 0] - Firstname: [lindex $row 1] Lastname: [lindex $row 2] Info: [lindex $row 3] - Added [duration [expr [clock seconds] - [lindex $row 4]]] ago"
}...


@speechles:
Not to be rude, but what have you been smoking tonight? Wink


Edit: Fixed list index typo
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Sun Jun 01, 2008 4:55 pm    Post subject: Reply with quote

nml375: I didn't do anything else than change -list to -flatlist and everything works? Very Happy pretty impressive. Thanks, how can i know next time if i should use -flatlist or just -list?
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 Jun 01, 2008 5:02 pm    Post subject: Reply with quote

nml375 wrote:
speechles:
Not to be rude, but what have you been smoking tonight? Wink


http://ereader.kiczek.com/little_girls.jpg

Only they aren't so little anymore, and have gone on to have children of their own. I expect being dutch you have some women of this kind you keep pampered. Wink
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Jun 01, 2008 5:05 pm    Post subject: Reply with quote

Well, as I illustrated in my post, either way works, just as long as you write the rest of your code properly...

The following is copied from the tclmysql manual, which should illustrate the difference between the two different options:
Code:
% ::mysql::sel $db "SELECT ID, NAME FROM FRIENDS" -list
{1 Joe} {2 Phil} {3 John}
% ::mysql::sel $db "SELECT ID, NAME FROM FRIENDS" -flatlist
{1 Joe 2 Phil 3 John}


With -list, you get a tcl-list, where each list-item is itself a tcl-list representing one row - having one list item for each column.
Or, in other words, to select the data in row x column y, you would use "puts stdout [lindex [lindex $result x] y]"

With -flatlist however, you get a tcl-list where each list-items represents one datacell. As the name suggests, the list have been "flattened", where each datacell follows the previous one (making it ideal for "foreach {nick fname lname info time} {" kind of structures, which will extract 5 elements from the list on each run).
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Jun 01, 2008 5:09 pm    Post subject: Reply with quote

speechles wrote:
...
I expect being dutch you have some women of this kind you keep pampered. Wink

Lol, sorry to disappoint you, but I'm "the Swedish Guy" Wink
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Sun Jun 01, 2008 5:19 pm    Post subject: Reply with quote

Could i do something like this:
if ("$chan" == "#somechannel"){set limit "5"}
and then use $limit in the select query?
to be honest i have tried, but got "extra characters after close-quote" and "after close-brace" why's that?
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 Jun 01, 2008 6:00 pm    Post subject: Reply with quote

Code:
if {[string match $chan "#somechannel"]} { set limit 5 }

You used parenthesis in place of curly braces, this should work better. You only really need to use "quotes" when encapsulating spaces or oddball characters into a single field.
_________________
speechles' eggdrop tcl archive


Last edited by speechles on Sun Jun 01, 2008 6:04 pm; edited 1 time in total
Back to top
View user's profile Send private message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Sun Jun 01, 2008 6:03 pm    Post subject: Reply with quote

Hmm
Code:

if {[string match $chan "#blah"]}{set limit 5}

set search [mysqlsel $dbconnect "SELECT nick,fname,lname,info,time FROM table WHERE nick LIKE '$nick%' LIMIT $limit" -flatlist]

Giving me this error AGAIN. Wondering why it should be that hard to make a little limit!
Quote:

Tcl error [pub:infouser] extra characters after close-brace
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 -> Scripting Help All times are GMT - 4 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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