]> git.donarmstrong.com Git - infobot.git/blobdiff - scripts/txt2mysql.pl
* Merged r1666:1760 from src-cleanup branch
[infobot.git] / scripts / txt2mysql.pl
index 68b134d5985e9e056f8c7e2ef33f78cd26b5a900..70e3744c1cc049304c3209d39efc596f77d370ca 100755 (executable)
@@ -9,47 +9,52 @@ require "src/Files.pl";
 require "src/Misc.pl";
 require "src/Factoids/DBCommon.pl";
 
-if (!scalar @ARGV) {
-  print "Usage: txt2mysql.pl <input.txt>\n";
-  exit 0;
+if ( !scalar @ARGV ) {
+    print "Usage: txt2mysql.pl <input.txt>\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 (<IN>) {
-  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;