]> git.donarmstrong.com Git - infobot.git/commitdiff
* Fixed script for importing factpacks
authordjmcgrath <djmcgrath@c11ca15a-4712-0410-83d8-924469b57eb5>
Sun, 25 Jan 2009 02:05:38 +0000 (02:05 +0000)
committerdjmcgrath <djmcgrath@c11ca15a-4712-0410-83d8-924469b57eb5>
Sun, 25 Jan 2009 02:05:38 +0000 (02:05 +0000)
- should now use needed infobot startup code
- converts tabs to spaces now
- deals with comments and empty lines
- rename of insertDB.pl to factpack.pl in next commit

git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@1857 c11ca15a-4712-0410-83d8-924469b57eb5

ChangeLog
scripts/insertDB.pl

index 749fd2d2fa86680abffbd544dd3602dd42660416..ff2ced08c633538fda37d1bc4a424caa298e3290 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 1.5.4
 =====
+* scripts/insertDB.pl
+- renamed to factpack.pl
+- should work properly now (needs testing)
+
 * Updates to DebianExtra.pl:
 - use soap for bug_info
 - totally replace do_id with the copy from DebianBugs.pl
index 1206414f4fb904726e52586357fbb8310e09bf8f..6bb60d9fed82562d15b51979becef8756a56a9f1 100755 (executable)
@@ -3,36 +3,81 @@
 $| = 1;
 
 use strict;
+use vars qw($bot_base_dir $bot_src_dir $bot_misc_dir $bot_state_dir
+  $bot_data_dir $bot_config_dir $bot_log_dir $bot_run_dir
+    $bot_pid $memusage %param
+);
 
-require "src/core.pl";
-require "src/logger.pl";
-require "src/modules.pl";
-require "src/Factoids/DBCommon.pl";
 
-&loadConfig( $bot_config_dir . "/infobot.config" );
+# Check for arguments
+if ( !scalar @ARGV ) {
+    print "Usage: $0 <pack1.fact> [<pack2.fact> <pack2.fact> ...]\n";
+    print "Example: $0 areacodes.fact usazips.fact\n";
+    exit 1;
+}
+
+
+# set any $bot_*_dir var's
+$bot_base_dir   = '.';
+$bot_config_dir = 'files/';
+$bot_data_dir   = 'files/';
+$bot_state_dir  = 'files/';
+$bot_run_dir    = '.';
+$bot_src_dir    = "$bot_base_dir/src";
+$bot_log_dir    = "$bot_base_dir/log";
+$bot_misc_dir   = "$bot_base_dir/files";
+$bot_pid        = $$;
+
+require "$bot_src_dir/logger.pl";
+require "$bot_src_dir/core.pl";
+require "$bot_src_dir/modules.pl";
+
+# Initialize enough to get DB access
+&setupConfig();
+&loadCoreModules();
 &loadDBModules();
+&loadFactoidsModules();
+&setup();
 
-unless (@_) {
-    print "hrm.. usage\n";
+if ( !scalar @ARGV ) {
+    print "Usage: $0 <pack1.fact> [<pack2.fact> <pack2.fact> ...]\n";
+    print "Example: $0 areacodes.fact usazips.fact\n";
     exit 0;
 }
 
-foreach (@_) {
+foreach (@ARGV) {
     next unless ( -f $_ );
+    my $file = $_;
 
-    open( IN, $_ ) or die "error: cannot open $_\n";
-    print "Opened $_ for input...\n";
+    open( IN, $file ) or die "error: cannot open $file\n";
+    print "Opened $file for input...\n";
 
     print "inserting... ";
     while (<IN>) {
-        next unless (/^(.*?) => (.*)$/);
+        chomp;
+        next if /^#/;
+        next unless (/=>/);
+
+        # Split into "key => value" pairs
+        my ($key, $value) = split(/=>/,$_,2);
+
+        # Strip extra begin/end whitespace
+        $key =~ s/^\s*(.*?)\s*$/$1/;
+        $value =~ s/^\s*(.*?)\s*$/$1/;
+        
+        # convert tabs
+        $key =~ s/\t/ /g;
+        $value =~ s/\t/ /g;
 
         ### TODO: check if it already exists. if so, don't add.
-        &setFactInfo( $1, "factoid_value", $2 );
-        print ":: $1 ";
+        ### TODO: combine 2 setFactInfo's into single
+        &setFactInfo( $key, "factoid_value", $value );
+        &setFactInfo( $key, "created_by", $file );
+        print ":: $key ";
     }
 
     close IN;
 }
+print "...Done!\n";
 
 # vim:ts=4:sw=4:expandtab:tw=80