X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Ftxt2mysql.pl;h=70e3744c1cc049304c3209d39efc596f77d370ca;hb=0b8cc0cae8719a4a06ee34ec6bd99f911efc1d9c;hp=88ace259d9293a483a099d866f95a62ea5d4c4fb;hpb=0a03234c837cefef8cd59c3f078e8a1732ae35c9;p=infobot.git diff --git a/scripts/txt2mysql.pl b/scripts/txt2mysql.pl index 88ace25..70e3744 100755 --- a/scripts/txt2mysql.pl +++ b/scripts/txt2mysql.pl @@ -9,49 +9,56 @@ require "src/Files.pl"; require "src/Misc.pl"; require "src/Factoids/DBCommon.pl"; -if (!scalar @ARGV) { - print "Usage: txt2mysql.pl \n"; - exit 0; +if ( !scalar @ARGV ) { + print "Usage: txt2mysql.pl \n"; + exit 0; } # open the txtfile. my $txtfile = shift; -open(IN,$txtfile) or die "error: cannot open txtfile '$txtfile'.\n"; +open( IN, $txtfile ) or die "error: cannot open txtfile '$txtfile'.\n"; # read the bot config file. &loadConfig("files/infobot.config"); &loadDBModules(); -&openDB($param{'DBName'}, $param{'SQLUser'}, $param{'SQLPass'}); +&openDB( $param{'DBName'}, $param{'SQLUser'}, $param{'SQLPass'} ); ### now pipe all the data to the mysql server... my $i = 1; print "converting factoid db to mysql...\n"; while () { - chop; - next if !length; - if (/^(.*)\s+=>\s+(.*)$/) { - # verify if it already exists? - my ($key,$val) = ($1,$2); - if ($key =~ /^\s*$/ or $val =~ /^\s*$/) { - print "warning: broken => '$_'.\n"; - next; - } + chop; + next if !length; + if (/^(.*)\s+=>\s+(.*)$/) { - if (&IsParam("freshmeat") and &dbGet("freshmeat", "name", $key, "name")) { - if (&getFactoid($key)) { - &delFactoid($key); - } - } else { - &setFactInfo(lc $key, "factoid_value", $val); - $i++; - } + # verify if it already exists? + my ( $key, $val ) = ( $1, $2 ); + if ( $key =~ /^\s*$/ or $val =~ /^\s*$/ ) { + print "warning: broken => '$_'.\n"; + next; + } + + if ( &IsParam("freshmeat") + and &dbGet( "freshmeat", "name", $key, "name" ) ) + { + if ( &getFactoid($key) ) { + &delFactoid($key); + } + } + else { + &setFactInfo( lc $key, "factoid_value", $val ); + $i++; + } - print "$i... " if ($i % 100 == 0); - } else { - print "warning: invalid => '$_'.\n"; - } + print "$i... " if ( $i % 100 == 0 ); + } + else { + print "warning: invalid => '$_'.\n"; + } } close IN; print "Done.\n"; &closeDB(); + +# vim:ts=4:sw=4:expandtab:tw=80