]> git.donarmstrong.com Git - infobot.git/blob - scripts/txt2mysql.pl
dunno
[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/infobot.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
34         # verify if it already exists?
35         my ( $key, $val ) = ( $1, $2 );
36         if ( $key =~ /^\s*$/ or $val =~ /^\s*$/ ) {
37             print "warning: broken => '$_'.\n";
38             next;
39         }
40
41         if (    &IsParam("freshmeat")
42             and &dbGet( "freshmeat", "name", $key, "name" ) )
43         {
44             if ( &getFactoid($key) ) {
45                 &delFactoid($key);
46             }
47         }
48         else {
49             &setFactInfo( lc $key, "factoid_value", $val );
50             $i++;
51         }
52
53         print "$i... " if ( $i % 100 == 0 );
54     }
55     else {
56         print "warning: invalid => '$_'.\n";
57     }
58 }
59 close IN;
60
61 print "Done.\n";
62 &closeDB();
63
64 # vim:ts=4:sw=4:expandtab:tw=80