Re: LSX Command > Add text to file

"Jochen Ritzel" <[email protected]> Tue, 11 Dec 2007 15:32:16 +0100
Newsgroups gmane.comp.windows.shells.litestep
Message-ID <op.t26db2ecd9nuum@w00t>
Some Lua:
[code, copy to some file and *luascriptfile it]
-- config this.
local clienttracker = {
     OUTFILE = 'blah.txt',
     -- if you want some formatting, you can set that here
     INFORMAT = '%s*([^>]*) > (.*)%s*', -- the input string is parsed with  
this pattern
     OUTFORMAT = '%s | %s',          -- and formatted with this pattern  
afterwards ... you could add tabs ( \t ) here ...
     TIMESTAMP = true,
     TIMEFORMAT = '%c', --see  
http://www.thinkage.ca/english/gcos/expl/c/lib/strfti.html
     ERROR = function(self, msg )     -- if an error occures, it is  
reported with this function
         --lslua.message_box("An Error occured: ".. msg, "Error!" )
         print( "An Error occured:", msg )
     end
}

-- admire this.
function clienttracker:_format( client, text )
     local s = self.OUTFORMAT:format( client, text)
     if self.TIMESTAMP then
         return ('%s: %s\n'):format( os.date( self.TIMEFORMAT), s )
     else
         return s
     end
end
function clienttracker:parse( s )
     local ok, client, text = pcall( string.match, s, self.INFORMAT )
     if not ok then return self:ERROR( client ) end
     ok, text = pcall( self.add, self, client, text )
     if not ok then return self:ERROR( text ) end
end
function clienttracker:add( client, text )
         local fp = io.open(self.OUTFILE, "a")
         fp:write( self:_format( client, text ) )
         fp:close()
end

-- rename this.
function bang_tracker( s )
     return clienttracker:parse( s )
end
[/code]

Usage:
!tracker "You > I wrote you some code."

Should be very easy to understand and expand ... hf

--thc4k


On Mon, 10 Dec 2007 20:22:39 +0100, Ace McKool <[email protected]> wrote:

> Hi Everyone,
>
> I'm trying to track my time at work.  I was hoping to use LSXCommand  
> (plus
> any needed modules) to do something like:
>
> ?tracker "Some Client > I did this for them"
>
> And it would simply write the string to a file and add a timestamp if
> possible.
>
> Anybody have any recommendations on how to get this started?  Thanks!



---------------------------------------------------------------------
    Can't Unsubscribe? Check http://desktopian.org/listunsub.html
        LS List Homepage: http://wuzzle.org/list/litestep.php
            Get the LS FAQ: http://lsfaq.shellfront.org