2017-11-19 23:00 GMT+01:00 jungle boogie <jungleboog...@gmail.com>:

> Thus said Cecil Westerhof on Sat, 18 Nov 2017 14:43:23 +0100
>
>> I found the benefits for TCL/TK. But this is a SQLite mailing list, so not
>> the right place to ask questions if it is not connected to SQLite also.
>> What would be good resources for TCL/TK?
>>
>>
> There's also a pretty active IRC room on freenode, it's #tcl.
>
> Let us know how your experiences go with tcl.


​I like it very much. It is a bit get used to, but I will manage I think.
;-)

One think I like that global variables are not default exposed in
procedures.

I wrote something to help me choose which (of my about 30) teas I am going
to brew. ;-)
 ​

​I also wrote a program to store systems statistics in a SQLite database:
​    #!/usr/bin/env tclsh

    ### Improvements
    # Get database from conf-file


    package require sqlite3


    proc getCPUTemp {} {
        if {1 != [regexp -all -line {^CPU_TEMP: +\+([0-9.]+)°C } [exec
sensors] -> temp]} {
            error {Did not get exactly a single temperature line from [exec
sensors] output}
        }
        return ${temp}
    }

    proc storeCPUTemp {} {
        storeMessage cpu-temp [getCPUTemp]
    }

    proc storeMessage {type message} {
        db eval "
          INSERT INTO messages
          (type, message)
          VALUES
          (:type, :message)
    "
    }

    proc storeSwap {} {
        storeMessage swap-usage [exec swapon --noheadings --show]
    }

    if {$argc != 1} {
        error "Error: ${argv0} DATABASE"
    }
    sqlite db  [lindex $argv 0]
    while {true} {
        after [expr 1000 * (60 - [clock format [clock seconds] -format %S])]
        set   currentSeconds [clock seconds]
        db transaction {
            storeCPUTemp
            # At the whole hour we save swap usage
            if {[clock format ${currentSeconds} -format %M] == "00"} {
                storeSwap
            }
        }
    }
    # Not really necessary because the above loop never ends
    # But I find this more clear and is robuster against change
    db close

​I am open for improvements.​

-- 
Cecil Westerhof
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to