Mercurial > hg > egg-tcls
view convert_feeds_db.tcl @ 177:7298af94e9c4
Added signature for changeset eda776bcb7ed
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 03 Jun 2014 13:06:48 +0300 |
parents | 4c51eeba993f |
children |
line wrap: on
line source
#!/usr/bin/tclsh # TCL script for converting Feed databases from # flatfile format to SQLite3 database. # # Written by Matti 'ccr' Hamalainen <ccr@tnsp.org> # (C) Copyright 2011 Tecnic Software productions (TNSP) # package require sqlite3 source [file dirname [info script]]/util_convert.tcl ### Check commandline arguments if {$argc != 2} { puts "Usage: $argv0 <input_flat_file_db> <output_sqlite_db_file>" exit 0 } set db_input [lindex $argv 0] set db_output [lindex $argv 1] ### Ask for confirmation puts "Conversion of '$db_input' to SQLite database '$db_output'." puts "NOTICE! This WILL destroy the current data in the target database!" if {![confirm_yesno "Proceed"]} { exit 0 } ### Open flatfile for reading if {[catch {set fd [open $db_input r]} uerrmsg]} { puts "Could not open file '$db_input' for reading: $uerrmsg" exit 1 } ### Open SQLite database, drop old tables, create new open_db $db_output drop_table_feeds create_table_feeds ### Convert data puts -nonewline "Converting database, please wait " set nline 0 seek $fd 0 start while {![eof $fd]} { incr nline gets $fd uline set items [split $uline "½"] if {[llength $items] == 4} { set sql "INSERT INTO feeds (feed,utime,url,title) VALUES ('[lescape $items 1]', [lindex $items 0], '[lescape $items 2]', '[lescape $items 3]')" if {[catch {dbh eval $sql} uerrmsg]} { puts "\nError ($nline): $uerrmsg on:\n$sql" exit 15 } } if {[expr $nline % 10] == 1} { puts -nonewline "." flush stdout } } dbh close close $fd puts "DONE."