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.

add up lines in txt and report total lines

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
w
whittinghamj
Op
Posts: 103
Joined: Sun May 21, 2006 4:50 pm

add up lines in txt and report total lines

Post by whittinghamj »

hi guys.

I been looking thro the forums and the archive but not sure what I would be looking for in the code.

I have a txt file with lets say 15 lines of info on it. I need a script that would open the file add the lines up close the file then report to the channel

<bot>There are 15 records in total

also i am stuck on how to stripcodes c

i have been going around and around in bllod circles for hours

here is what i am working with.

Code: Select all

proc add {nick uhost hand chan text} {
        set database [open ${::db} a+]
        set timestamp [clock format [clock seconds]]
        set section [lindex $text 6]
        puts $database "$timestamp $section"
        close $database
}
[code]

I know i have to change the line added to the database but not sure how.

Any help would be great.

Cheers

Quest
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Code: Select all

proc getlines {nick uhost hand chan text} {
        set file [open "YOURFILE" r]
        set data [split [read $file] \n]
        close $file
        puthelp "PRIVMSG $chan :number of lines: [llength $data]"
}

Code: Select all

proc addtimestamp {nick uhost hand chan text} {
       set file [open "YOURFILE" a]
       set timestamp [clock format [clock seconds]]
       set section [lindex $text 6]
       puts $file "$timestamp $section"
       close $file
}
Of course, the above addtimestamp thing doesn't do any kind of sanity checking on your input, nor does it do any security checking on who can run it (but you could just limit access with the bind for it..) I made 2 seperate procs because your request was unclear, and it seemed like you wanted 1 proc for counting lines, and another for adding stuff to the file.

As far as how to use the stripcode command, you have to feed it strings, what are you trying to strip? Log files? Gnenerally, you want to make a seperate binding to get the public messages and pass them through a proc with stripcodes, then write them out to a file (although, I'd probably cache the data in memory and use the various EVNT bindings to write the cache out before quit, rehash, etc. and maybe a timer to write the log periodically..
w
whittinghamj
Op
Posts: 103
Joined: Sun May 21, 2006 4:50 pm

Post by whittinghamj »

thank you for the help - worked perfectly and I understand regarding the unixtime. I did some reading up at work today.

I have one other question.

I have the following code to record text from a channel and save it to a file. To record !command 's being used.

Code: Select all

proc add {nick uhost hand chan text} {
        set database [open ${::db} a+]
        set date [unixtime]
        set command [lindex $text 0 end]
        puts $database "$date $command"
        close $database
}
The db file looks like

123431234 !command something was used

What I wanted to do was findout how to replace the spaces with a " . "

So instead of it being 1234566 one two three it would be
123456 one.two.three

the text on the channel has spaces but I need those spaces converting into periods for saving to the file.

Any help would be amazing.

Thanks

also - I store the time when the command was used. How would I go about checking the time passed since the unixtime time saved in the file to the present - eg 1week 2days 52 minutes ago t!command was used.

Any help please - cheers

Jamie aka Quest
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

The question about replacing spaces with dots, was answered in another thread, basically just use string map:

set myvar [string map {" " "."} $input]

As far as find the duration from a time stamp, take a look at the 'duration' command :)

duration <seconds>
Returns: the number of seconds converted into years, weeks, days, hours, minutes, and seconds. 804600 seconds is turned into 1 week 2 days 7 hours 30 minutes.
Module: core

The following assumes you grabbed your previous timestamp already, in a var called '$then'

Get the current timestamp,

set now [unixtime]

then subtract your previous timestamp,

set timesince [expr $now - $then]

and then use duration to check the time difference:

set duration [duration $timesince]

Or, in a one-liner:

set timesince [duration [expr $then - [unixtime]]]
Post Reply