File: txt2mysql.pl

package info (click to toggle)
blootbot 1.1.0-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,420 kB
  • ctags: 586
  • sloc: perl: 15,941; sh: 154; makefile: 56; sql: 45
file content (57 lines) | stat: -rwxr-xr-x 1,212 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl
# by the xk.
#

require "src/core.pl";
require "src/logger.pl";
require "src/modules.pl";
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;
}

# open the txtfile.
my $txtfile = shift;
open(IN,$txtfile) or die "error: cannot open txtfile '$txtfile'.\n";

# read the bot config file.
&loadConfig("files/blootbot.config");
&loadDBModules();
&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;
    }

    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";
  }
}
close IN;

print "Done.\n";
&closeDB();