Revision [16096]

This is an old revision of RandomCommentGenerator made by BrianKoontz on 2007-02-12 11:07:40.

 

Random Comment Generator


This is a little perl script I threw together to generate random nested comments for threaded comment testing. I thought others might find it useful (mainly developers, or disgruntled employees), so here it is. Use at your own risk!

generateWikkaComments.pl
#! /usr/bin/perl
#
# generateWikkaComments.pl -- Generate random comments for stress
# testing
#
# Usage: generateWikkaComments -n <number of comments> -s <starting
# id> -p <page tag> -u <user>
#
# Note: Create the first comment for a page to establish the value
# used for -s! (You will need to access the comments table in MySQL for this id.)
#
#####################################################################

use strict;
use DBI();
use Text::Greeking;
use POSIX qw(strftime);
use Getopt::Std;
use vars qw($opt_n $opt_s $opt_p $opt_u);
getopts("n:s:p:u:");

### Modify these ###

# Wikka DB
#my $wikka_database = "wikka";
#my $wikka_host = "127.0.0.1";
#my $wikka_username = "wikkauser";
#my $wikka_password = "wikka_pass";
#my $wikka_table_prefix = "wikka"; #No underscore!

my $RaiseError = 1;

### End modifications ###
my $dbh = DBI->connect("DBI:mysql:database=$wikka_database; host=$wikka_host",
							 "$wikka_username", "$wikka_password",
							 {'RaiseError' => $RaiseError});
my $sth = $dbh->prepare("INSERT INTO ${wikka_table_prefix}_comments (page_tag, time, comment, user, parent) VALUES(?,?,?,?,?)");

my $parents = [];
push(@$parents, "NULL");
push(@$parents, $opt_s);
for(my $i=0; $i<$opt_n; ++$i) {
	my $comment = &generateRandomComment;
	chomp $comment;
	my $parent = $parents->[&randomizeInt(0, scalar(@$parents)-1)];
	my $time = strftime "%F %H:%M:%S", localtime;
	$sth->execute($opt_p, $time, $comment, $opt_u, $parent);
	push(@$parents, ++$opt_s);
	#print "INSERT INTO ${wikka_table_prefix}_comments VALUES('$opt_p', '$time', '$comment', '$opt_u', $parent)";
}

$dbh->disconnect;

sub generateRandomComment {
	my $g = Text::Greeking->new;
	$g->paragraphs(1,2);
	$g->sentences(2,5);
	$g->words(8,16);
	return $g->generate;
}

# Return a random int in range of ll to ul, inclusive
sub randomizeInt {

	my( $ll, $ul ) = @_;
	return $ll + int( rand( $ul - $ll ) );
}
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki