]> git.donarmstrong.com Git - infobot.git/blob - scripts/txt2mysql.pl
47a70b7437c0b24d18a4a3ad0da0a953bab60442
[infobot.git] / scripts / txt2mysql.pl
1 #!/usr/bin/perl
2 # by the xk.
3 #
4
5 require "src/core.pl";
6 require "src/logger.pl";
7 require "src/modules.pl";
8 require "src/Files.pl";
9 require "src/Misc.pl";
10 require "src/Factoids/DBCommon.pl";
11
12 if (!scalar @ARGV) {
13   print "Usage: txt2mysql.pl <input.txt>\n";
14   exit 0;
15 }
16
17 # open the txtfile.
18 my $txtfile = shift;
19 open(IN,$txtfile) or die "error: cannot open txtfile '$txtfile'.\n";
20
21 # read the bot config file.
22 &loadConfig("files/blootbot.config");
23 &loadDBModules();
24 &openDB($param{'DBName'}, $param{'SQLUser'}, $param{'SQLPass'});
25
26 ### now pipe all the data to the mysql server...
27 my $i = 1;
28 print "converting factoid db to mysql...\n";
29 while (<IN>) {
30   chop;
31   next if !length;
32   if (/^(.*)\s+=>\s+(.*)$/) {
33     # verify if it already exists?
34     my ($key,$val) = ($1,$2);
35     if ($key =~ /^\s*$/ or $val =~ /^\s*$/) {
36         print "warning: broken => '$_'.\n";
37         next;
38     }
39
40     if (&IsParam("freshmeat") and &dbGet("freshmeat", "name", $key, "name")) {
41         if (&getFactoid($key)) {
42             &delFactoid($key);
43         }
44     } else {
45         &setFactInfo(lc $key, "factoid_value", $val);
46         $i++;
47     }
48
49     print "$i... " if ($i % 100 == 0);
50   } else {
51     print "warning: invalid => '$_'.\n";
52   }
53 }
54 close IN;
55
56 print "Done.\n";
57 &closeDB();